ltheoret
11-02-2014, 21:07
Hi,
I am working with a encyclopaedia of about 54000 records. This takes about 4 seconds to load and configure. Is there a way I could put a splash screen at the start and get rid of the Console all together. I am not a fan of software that do not show life write from the start.
Here is my code:
' Basic Template for custom dialog
' Start Date 12-25-2013
' Created by Luc Theoret
'------------------------------------------------------------------------------
'thinAir Visual Designer
'------------------------------------------------------------------------------
' Project: Visual Designer generated code
' File: Your file name
' Created: On 12-25-2013 at 21:44:14
'------------------------------------------------------------------------------
'---Needed thinBasic modules
Uses "Console"
Uses "UI"
Uses "File"
'---Controls IDs---
Begin ControlID
%IDC_LISTBOX_1
%IDC_STATICLABEL_1
%IDC_EDIT_SEARCH
%IDC_BUTTON_SEARCH
%IDC_EDIT_TOPIC
%IDC_BUTTON_CLOSE
%IDC_EDIT_DISP
End ControlID
Global Records As Long
Global Index() As String
Global Dict() As String
'------------------------------------------------------------------------------
' Main thinBasic function
'------------------------------------------------------------------------------
Function TBMain() As Long
Dim FileName As String
Dim tick, tack As Long
Dim Total As Double
FileName = APP_ScriptPath + "Data Sort.dat" ' Build filename
If Not(FILE_Exists(FileName)) Then
PrintL
PrintL "Cannot find input file: " + FileName
PrintL "program terminated"
PrintL "Press any key..."
While Not Console_InKey
Wend
Stop
End If
PrintL "Loading file: " + "Data.dat" + " ..."
tick = GetTickCount
Records = LoadFile(FileName)
tack = GetTickCount
Total = (tack-tick)/1000
PrintL "File Loaded - " + Records + " Records loaded " + Total + " Secounds"
' PrintL "Sorting Records ..."
' tick = GetTickCount
' Adv_Bubble()
' tack = GetTickCount
' Total = (tack-tick)/1000
' Print: "Sorting done" + Total + " Secounds"
MainWindow_Create(%HWND_DESKTOP)
End Function
'------------------------------------------------------------------------------
' Create main Window
'------------------------------------------------------------------------------
Function MainWindow_Create(ByVal hParent As Long) As Long
Local hDlg As Long
Local hFont As Long
Local lStyle As Long
Local lStyleEx As Long
lStyle = _
%WS_DLGFRAME | _
%WS_CAPTION | _
%WS_SYSMENU | _
%WS_OVERLAPPEDWINDOW | _
%WS_CLIPCHILDREN | _
%WS_CLIPSIBLINGS | _
%DS_CENTER
lStyleEx = 0
Local Tick, Tack As Long
Local Total As Double
Dialog New Pixels, hParent, "Probert Encyclopaedia", -1, -1, 602, 402, lStyle, lStyleEx, To hDlg
'---Set the minimum size of the dialog
Dialog Set MinClientSize hDlg, 602, 402
hFont = Font_Create("MS Sans Serif", 8)
Dialog Send hDlg, %WM_SETFONT, hFont, 0
Control Add LISTBOX, hDlg, %IDC_LISTBOX_1, , 8, 8, 152, 384, %WS_BORDER Or %WS_CHILD Or %WS_CLIPSIBLINGS Or %WS_TABSTOP Or %WS_VISIBLE Or %WS_VSCROLL Or %LBS_NOINTEGRALHEIGHT Or %LBS_NOTIFY, %WS_EX_RIGHTSCROLLBAR
Control Add Label, hDlg, %IDC_STATICLABEL_1, "Search", 168, 8, 80, 24, %WS_CHILD Or %WS_CLIPSIBLINGS Or %WS_VISIBLE Or %SS_NOTIFY, 0
Control Add Textbox, hDlg, %IDC_EDIT_SEARCH, "Search", 248, 8, 248, 24, %WS_CHILD Or %WS_CLIPSIBLINGS Or %WS_TABSTOP Or %WS_VISIBLE, %WS_EX_CLIENTEDGE
Control Add Button, hDlg, %IDC_BUTTON_SEARCH, "Search", 504, 8, 88, 24, %WS_CHILD Or %WS_CLIPSIBLINGS Or %WS_TABSTOP Or %WS_VISIBLE Or %BS_PUSHBUTTON, 0
Control Add Textbox, hDlg, %IDC_EDIT_TOPIC, "Topic", 168, 40, 328, 24, %ES_READONLY Or %ES_AUTOVSCROLL Or %ES_MULTILINE Or %WS_VSCROLL, %WS_EX_CLIENTEDGE
Control Add Button, hDlg, %IDC_BUTTON_CLOSE, "Close", 504, 40, 88, 24, %WS_CHILD Or %WS_CLIPSIBLINGS Or %WS_TABSTOP Or %WS_VISIBLE Or %BS_PUSHBUTTON, 0
Control Add Textbox, hDlg, %IDC_EDIT_DISP, "Topic", 168, 72, 424, 320, %ES_READONLY Or %ES_AUTOVSCROLL Or %ES_MULTILINE Or %WS_VSCROLL, %WS_EX_CLIENTEDGE
Control Set Resize hDlg, %IDC_LISTBOX_1 , 0, 0, 1, 1
Control Set Resize hDlg, %IDC_EDIT_DISP , 1, 1, 1, 1
PrintL "Loading ListBox ..."
tick = GetTickCount
SampleListBox(hDlg, %IDC_LISTBOX_1, Records)
tack = GetTickCount
Total = (tack-tick)/1000
PrintL "Done " + Total + " Secounds"
Dialog Show Modal hDlg, Call MainWindow_Proc
Win_DeleteObject hFont
End Function
'------------------------------------------------------------------------------
' Main WIndow CallBack handler
'------------------------------------------------------------------------------
CallBack Function MainWindow_Proc() As Long
Local tmpStr As String
Local tmpLong As Long
Local pNMHDR As NMHDR Ptr
Local PageNo As Long
Local hFontTab As Long
Select Case (CBMSG)
Case %WM_INITDIALOG
Control Set Text CBHNDL, %IDC_EDIT_TOPIC, Index(1)
Control Set Text CBHNDL, %IDC_EDIT_DISP, Dict(1)
Case %WM_COMMAND
Select Case CBCTL
Case %IDC_LISTBOX_1
Select Case CBCTLMSG
Case %LBN_SELCHANGE
LISTBOX Get Text CBHNDL, %IDC_LISTBOX_1 To tmpStr
LISTBOX Get Selected CBHNDL, %IDC_LISTBOX_1 To tmpLong
Control Set Text CBHNDL, %IDC_EDIT_TOPIC, tmpStr
Control Set Text CBHNDL, %IDC_EDIT_DISP, Dict(tmpLong)
End Select
Case %IDC_BUTTON_SEARCH
Control Set Text CBHNDL, %IDC_BUTTON_SEARCH, "Searching ..."
Control Get Text CBHNDL, %IDC_EDIT_SEARCH To tmpStr
tmpLong = SearchDict(tmpStr)
If tmpLong > 0 Then
Control Set Text CBHNDL, %IDC_EDIT_TOPIC, Index(tmpLong)
Control Set Text CBHNDL, %IDC_EDIT_DISP, Dict(tmpLong)
Else
tmpStr = tmpStr + " Not Found"
Control Set Text CBHNDL, %IDC_EDIT_SEARCH, tmpStr
End If
Control Set Text CBHNDL, %IDC_BUTTON_SEARCH, "Search"
Case %IDC_BUTTON_CLOSE
Dialog End CBHNDL
End Select
Select Case LOWRD(CBWPARAM)
Case %IDOK
Case %IDCANCEL
End Select
Case %WM_NOTIFY
Case %WM_DESTROY
End Select
End Function
'--------------------------------------------------------------------------------
' Load Encyclopaedia into the LixtBox
'--------------------------------------------------------------------------------
Function SampleListBox(ByVal hDlg As Long,ByVal lID As Long,ByVal lCount As Long) As Long
Local i As Long
For i = 1 To lCount - 1
LISTBOX Add hDlg, lID, Index(i)
Next i
End Function
'--------------------------------------------------------------------------------
' Load Dictionary
'--------------------------------------------------------------------------------
Function LoadFile(FileName As String) As Long
Local Temp As String
Local FileHandle As DWord
Local Count, CLoop As Long
FileHandle = FILE_Open(FileName, "INPUT")
Count = 1
While Not FILE_EOF(FileHandle)
Temp = FILE_LineInput(FileHandle)
Temp = FILE_LineInput(FileHandle)
Count = Count + 1
Wend
FILE_Close(FileHandle)
ReDim Index(Count - 1) As String
ReDim Dict(Count - 1) As String
FileHandle = FILE_Open(FileName, "INPUT")
Count = 1
While Not FILE_EOF(FileHandle)
Index(Count) = FILE_LineInput(FileHandle)
Dict(Count) = FILE_LineInput(FileHandle)
Count = Count + 1
Wend
FILE_Close(FileHandle)
For CLoop = 1 To Count - 1
Index(CLoop) = LTrim$(Index(CLoop), "*")
Next
Return Count
End Function
'--------------------------------------------------------------------------------
' Search Dictionary
'--------------------------------------------------------------------------------
Function SearchDict(ItemName As String) As Long
Static TmpCount, ItemLen As Long
Static TmpStr As String
TmpCount = 1
ItemName = Ucase$(ItemName)
ItemLen = Len(ItemName)
TmpStr = Ucase$(LEFT$(Index(TmpCount), ItemLen))
While TmpCount < (Records-1) And ItemName <> TmpStr
TmpCount = TmpCount + 1
TmpStr = Ucase$(LEFT$(Index(TmpCount), ItemLen))
Wend
If tmpCount = (Records-1) And ItemName <> TmpStr Then
Return -1
Else
Return TmpCount
End If
End Function
'--------------------------------------------------------------------------------
' Sort Dictionary
'--------------------------------------------------------------------------------
Function Adv_Bubble()
Local Count1, Count2 As Long
Local CleanPass As Integer = 0
Local TmpInd, TmpTopic As String
For Count1 = 1 To Records - 2 And Not CleanPass
CleanPass = 1
For Count2 = Count1 + 1 To Records - 1
If (Index(Count1) > Index(Count2)) Then
TmpInd = Index(Count1)
TmpTopic = Dict(Count1)
Index(Count1) = Index(Count2)
Dict(Count1) = Dict(Count2)
Index(Count2) = TmpInd
Dict(Count2) = TmpTopic
CleanPass = 0
End If
Next
Next
End Function
I am working with a encyclopaedia of about 54000 records. This takes about 4 seconds to load and configure. Is there a way I could put a splash screen at the start and get rid of the Console all together. I am not a fan of software that do not show life write from the start.
Here is my code:
' Basic Template for custom dialog
' Start Date 12-25-2013
' Created by Luc Theoret
'------------------------------------------------------------------------------
'thinAir Visual Designer
'------------------------------------------------------------------------------
' Project: Visual Designer generated code
' File: Your file name
' Created: On 12-25-2013 at 21:44:14
'------------------------------------------------------------------------------
'---Needed thinBasic modules
Uses "Console"
Uses "UI"
Uses "File"
'---Controls IDs---
Begin ControlID
%IDC_LISTBOX_1
%IDC_STATICLABEL_1
%IDC_EDIT_SEARCH
%IDC_BUTTON_SEARCH
%IDC_EDIT_TOPIC
%IDC_BUTTON_CLOSE
%IDC_EDIT_DISP
End ControlID
Global Records As Long
Global Index() As String
Global Dict() As String
'------------------------------------------------------------------------------
' Main thinBasic function
'------------------------------------------------------------------------------
Function TBMain() As Long
Dim FileName As String
Dim tick, tack As Long
Dim Total As Double
FileName = APP_ScriptPath + "Data Sort.dat" ' Build filename
If Not(FILE_Exists(FileName)) Then
PrintL
PrintL "Cannot find input file: " + FileName
PrintL "program terminated"
PrintL "Press any key..."
While Not Console_InKey
Wend
Stop
End If
PrintL "Loading file: " + "Data.dat" + " ..."
tick = GetTickCount
Records = LoadFile(FileName)
tack = GetTickCount
Total = (tack-tick)/1000
PrintL "File Loaded - " + Records + " Records loaded " + Total + " Secounds"
' PrintL "Sorting Records ..."
' tick = GetTickCount
' Adv_Bubble()
' tack = GetTickCount
' Total = (tack-tick)/1000
' Print: "Sorting done" + Total + " Secounds"
MainWindow_Create(%HWND_DESKTOP)
End Function
'------------------------------------------------------------------------------
' Create main Window
'------------------------------------------------------------------------------
Function MainWindow_Create(ByVal hParent As Long) As Long
Local hDlg As Long
Local hFont As Long
Local lStyle As Long
Local lStyleEx As Long
lStyle = _
%WS_DLGFRAME | _
%WS_CAPTION | _
%WS_SYSMENU | _
%WS_OVERLAPPEDWINDOW | _
%WS_CLIPCHILDREN | _
%WS_CLIPSIBLINGS | _
%DS_CENTER
lStyleEx = 0
Local Tick, Tack As Long
Local Total As Double
Dialog New Pixels, hParent, "Probert Encyclopaedia", -1, -1, 602, 402, lStyle, lStyleEx, To hDlg
'---Set the minimum size of the dialog
Dialog Set MinClientSize hDlg, 602, 402
hFont = Font_Create("MS Sans Serif", 8)
Dialog Send hDlg, %WM_SETFONT, hFont, 0
Control Add LISTBOX, hDlg, %IDC_LISTBOX_1, , 8, 8, 152, 384, %WS_BORDER Or %WS_CHILD Or %WS_CLIPSIBLINGS Or %WS_TABSTOP Or %WS_VISIBLE Or %WS_VSCROLL Or %LBS_NOINTEGRALHEIGHT Or %LBS_NOTIFY, %WS_EX_RIGHTSCROLLBAR
Control Add Label, hDlg, %IDC_STATICLABEL_1, "Search", 168, 8, 80, 24, %WS_CHILD Or %WS_CLIPSIBLINGS Or %WS_VISIBLE Or %SS_NOTIFY, 0
Control Add Textbox, hDlg, %IDC_EDIT_SEARCH, "Search", 248, 8, 248, 24, %WS_CHILD Or %WS_CLIPSIBLINGS Or %WS_TABSTOP Or %WS_VISIBLE, %WS_EX_CLIENTEDGE
Control Add Button, hDlg, %IDC_BUTTON_SEARCH, "Search", 504, 8, 88, 24, %WS_CHILD Or %WS_CLIPSIBLINGS Or %WS_TABSTOP Or %WS_VISIBLE Or %BS_PUSHBUTTON, 0
Control Add Textbox, hDlg, %IDC_EDIT_TOPIC, "Topic", 168, 40, 328, 24, %ES_READONLY Or %ES_AUTOVSCROLL Or %ES_MULTILINE Or %WS_VSCROLL, %WS_EX_CLIENTEDGE
Control Add Button, hDlg, %IDC_BUTTON_CLOSE, "Close", 504, 40, 88, 24, %WS_CHILD Or %WS_CLIPSIBLINGS Or %WS_TABSTOP Or %WS_VISIBLE Or %BS_PUSHBUTTON, 0
Control Add Textbox, hDlg, %IDC_EDIT_DISP, "Topic", 168, 72, 424, 320, %ES_READONLY Or %ES_AUTOVSCROLL Or %ES_MULTILINE Or %WS_VSCROLL, %WS_EX_CLIENTEDGE
Control Set Resize hDlg, %IDC_LISTBOX_1 , 0, 0, 1, 1
Control Set Resize hDlg, %IDC_EDIT_DISP , 1, 1, 1, 1
PrintL "Loading ListBox ..."
tick = GetTickCount
SampleListBox(hDlg, %IDC_LISTBOX_1, Records)
tack = GetTickCount
Total = (tack-tick)/1000
PrintL "Done " + Total + " Secounds"
Dialog Show Modal hDlg, Call MainWindow_Proc
Win_DeleteObject hFont
End Function
'------------------------------------------------------------------------------
' Main WIndow CallBack handler
'------------------------------------------------------------------------------
CallBack Function MainWindow_Proc() As Long
Local tmpStr As String
Local tmpLong As Long
Local pNMHDR As NMHDR Ptr
Local PageNo As Long
Local hFontTab As Long
Select Case (CBMSG)
Case %WM_INITDIALOG
Control Set Text CBHNDL, %IDC_EDIT_TOPIC, Index(1)
Control Set Text CBHNDL, %IDC_EDIT_DISP, Dict(1)
Case %WM_COMMAND
Select Case CBCTL
Case %IDC_LISTBOX_1
Select Case CBCTLMSG
Case %LBN_SELCHANGE
LISTBOX Get Text CBHNDL, %IDC_LISTBOX_1 To tmpStr
LISTBOX Get Selected CBHNDL, %IDC_LISTBOX_1 To tmpLong
Control Set Text CBHNDL, %IDC_EDIT_TOPIC, tmpStr
Control Set Text CBHNDL, %IDC_EDIT_DISP, Dict(tmpLong)
End Select
Case %IDC_BUTTON_SEARCH
Control Set Text CBHNDL, %IDC_BUTTON_SEARCH, "Searching ..."
Control Get Text CBHNDL, %IDC_EDIT_SEARCH To tmpStr
tmpLong = SearchDict(tmpStr)
If tmpLong > 0 Then
Control Set Text CBHNDL, %IDC_EDIT_TOPIC, Index(tmpLong)
Control Set Text CBHNDL, %IDC_EDIT_DISP, Dict(tmpLong)
Else
tmpStr = tmpStr + " Not Found"
Control Set Text CBHNDL, %IDC_EDIT_SEARCH, tmpStr
End If
Control Set Text CBHNDL, %IDC_BUTTON_SEARCH, "Search"
Case %IDC_BUTTON_CLOSE
Dialog End CBHNDL
End Select
Select Case LOWRD(CBWPARAM)
Case %IDOK
Case %IDCANCEL
End Select
Case %WM_NOTIFY
Case %WM_DESTROY
End Select
End Function
'--------------------------------------------------------------------------------
' Load Encyclopaedia into the LixtBox
'--------------------------------------------------------------------------------
Function SampleListBox(ByVal hDlg As Long,ByVal lID As Long,ByVal lCount As Long) As Long
Local i As Long
For i = 1 To lCount - 1
LISTBOX Add hDlg, lID, Index(i)
Next i
End Function
'--------------------------------------------------------------------------------
' Load Dictionary
'--------------------------------------------------------------------------------
Function LoadFile(FileName As String) As Long
Local Temp As String
Local FileHandle As DWord
Local Count, CLoop As Long
FileHandle = FILE_Open(FileName, "INPUT")
Count = 1
While Not FILE_EOF(FileHandle)
Temp = FILE_LineInput(FileHandle)
Temp = FILE_LineInput(FileHandle)
Count = Count + 1
Wend
FILE_Close(FileHandle)
ReDim Index(Count - 1) As String
ReDim Dict(Count - 1) As String
FileHandle = FILE_Open(FileName, "INPUT")
Count = 1
While Not FILE_EOF(FileHandle)
Index(Count) = FILE_LineInput(FileHandle)
Dict(Count) = FILE_LineInput(FileHandle)
Count = Count + 1
Wend
FILE_Close(FileHandle)
For CLoop = 1 To Count - 1
Index(CLoop) = LTrim$(Index(CLoop), "*")
Next
Return Count
End Function
'--------------------------------------------------------------------------------
' Search Dictionary
'--------------------------------------------------------------------------------
Function SearchDict(ItemName As String) As Long
Static TmpCount, ItemLen As Long
Static TmpStr As String
TmpCount = 1
ItemName = Ucase$(ItemName)
ItemLen = Len(ItemName)
TmpStr = Ucase$(LEFT$(Index(TmpCount), ItemLen))
While TmpCount < (Records-1) And ItemName <> TmpStr
TmpCount = TmpCount + 1
TmpStr = Ucase$(LEFT$(Index(TmpCount), ItemLen))
Wend
If tmpCount = (Records-1) And ItemName <> TmpStr Then
Return -1
Else
Return TmpCount
End If
End Function
'--------------------------------------------------------------------------------
' Sort Dictionary
'--------------------------------------------------------------------------------
Function Adv_Bubble()
Local Count1, Count2 As Long
Local CleanPass As Integer = 0
Local TmpInd, TmpTopic As String
For Count1 = 1 To Records - 2 And Not CleanPass
CleanPass = 1
For Count2 = Count1 + 1 To Records - 1
If (Index(Count1) > Index(Count2)) Then
TmpInd = Index(Count1)
TmpTopic = Dict(Count1)
Index(Count1) = Index(Count2)
Dict(Count1) = Dict(Count2)
Index(Count2) = TmpInd
Dict(Count2) = TmpTopic
CleanPass = 0
End If
Next
Next
End Function