|
-
May 8th, 2002, 06:44 PM
#1
Thread Starter
Hyperactive Member
Saving List count and retrieving?
Hi i have the following code...
For X = 0 To lstretri.ListCount - 1
lstretri.ListIndex = X
txtCluburl.Text = lstretri.List(X)
lblcurrent.Caption = "Current: " & lstretri.ListIndex
I want to put a piece of coding the the Form_Unload() to save the current Listbox Index to "hold.yem" if the program is accidently closed. Also I would like for the For statement to retrieve the number value of the Listbox Index that was save and plug it into the coding and continue from where it left off.
-
May 8th, 2002, 06:54 PM
#2
Try something like this
VB Code:
Private Sub Form_Unload(Cancel As Integer)
SaveSetting "MyApp", "FormName", "ListBoxName", List1.ListIndex
End Sub
Private Sub Form_Load()
Dim LIndex As String
LIndex = GetSetting("MyApp", "FormName", "ListBoxName")
If LIndex <> "" Then
List1.ListIndex = CInt(LIndex)
End If
End Sub
-
May 8th, 2002, 06:56 PM
#3
-= B u g S l a y e r =-
he might wanna know where the info is saved ??
-
May 8th, 2002, 08:37 PM
#4
Thread Starter
Hyperactive Member
can someone show me how to do the saving and loading using the text file "hold.yem"
-
May 8th, 2002, 11:36 PM
#5
Hyperactive Member
here is an example if you want to use an INI file
VB Code:
'module code
Option Explicit
Public Declare Function WritePrivateProfileString Lib "kernel32" Alias _
"WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal _
lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
Public Declare Function GetPrivateProfileString Lib "kernel32" Alias _
"GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal _
lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As _
String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Public Sub WriteToINI(Section As String, Key As String, KeyValue As String, _
Directory As String)
Call WritePrivateProfileString(Section$, UCase$(Key$), KeyValue$, Directory$)
End Sub
Public Function GetFromINI(Section As String, Key As String, Directory As String) As String
Dim strBuffer As String
strBuffer = String(750, Chr(0))
Key$ = LCase$(Key$)
GetFromINI$ = Left(strBuffer, GetPrivateProfileString(Section$, ByVal _
Key$, "", strBuffer, Len(strBuffer), Directory$))
End Function
use it like this
VB Code:
'form code
Option Explicit
Dim intListBoxCount As Integer
Private Sub Form_Load()
If Not Dir$((App.Path & "\hold.yem")) = "" Then intListBoxCount = Int(GetFromINI("Saved Values", "ListBox_Count", (App.Path & "\hold.yem")))
MsgBox Str(intListBoxCount)
End Sub
Private Sub Form_Unload(Cancel As Integer)
Call WriteToINI("Saved Values", "ListBox_Count", Str(lstretri.ListCount), (App.Path & "\hold.yem"))
End Sub
Let me know if this is what you were looking for.
-
May 9th, 2002, 03:16 AM
#6
Thread Starter
Hyperactive Member
Code:
Option Explicit
Dim intListBoxCount As Integer
Private Sub Form_Load()
If Not Dir$((App.Path & "\hold.yem")) = "" Then intListBoxCount = Int(GetFromINI("Saved Values", "ListBox_Count", (App.Path & "\hold.yem")))
MsgBox Str(intListBoxCount)
End Sub
Private Sub Form_Unload(Cancel As Integer)
Call WriteToINI("Saved Values", "ListBox_Count", Str(lstretri.ListCount), (App.Path & "\hold.yem"))
End Sub
Orginal loop from beginning
For X = 0 To lstretri.ListCount - 1
lstretri.ListIndex = X
txtCluburl.Text = lstretri.List(X)
lblcurrent.Caption = "Current: " & lstretri.ListIndex
how would i make the above For Loop statement start with the item number that "intListBoxCount" holds
-
May 9th, 2002, 03:30 AM
#7
Bouncy Member
VB Code:
assuming you've loaded it from the ini file
Orginal loop from beginning
For X = [u]intListCount[/u] To lstretri.ListCount - 1
lstretri.ListIndex = X
txtCluburl.Text = lstretri.List(X)
lblcurrent.Caption = "Current: " & lstretri.ListIndex
-
May 9th, 2002, 03:39 AM
#8
Hyperactive Member
Sorry I didn't read you first post correctly
VB Code:
Private Sub Form_Load()
If Not Dir$((App.Path & "\hold.yem")) = "" Then intListBoxCount = Int(GetFromINI("Saved Values", "ListBox_Count", (App.Path & "\hold.yem")))
For X = intListBoxCount To lstretri.ListCount - 1
Next X
End Sub
Private Sub Form_Unload(Cancel As Integer)
Call WriteToINI("Saved Values", "ListBox_Count", Str(lstretri.ListIndex), (App.Path & "\hold.yem"))
End Sub
-
May 9th, 2002, 01:58 PM
#9
Thread Starter
Hyperactive Member
Code:
If Not Dir$((App.Path & "\" + strName)) = "" Then
intListBoxCount = Int(GetFromINI("Saved Values", "ListBox_Count", (App.Path & "\" + strName)))
For x = intListBoxCount To lstretri.ListCount - 1
Else <-- ******************ERROR HERE!
For x = 0 To lstretri.ListCount - 1
End If
lstretri.ListIndex = x
txtCluburl.Text = lstretri.List(x)
lblcurrent.Caption = "Current: " & lstretri.ListIndex
why do i keep getting a Else without IF error.
-
May 9th, 2002, 02:07 PM
#10
Hyperactive Member
VB Code:
If Not Dir$((App.Path & "\" + strName)) = "" Then
intListBoxCount = Int(GetFromINI("Saved Values", "ListBox_Count", (App.Path & "\" + strName)))
For x = intListBoxCount To lstretri.ListCount - 1
' your code here
Next x 'you next to add next x
Else
For x = 0 To lstretri.ListCount - 1
' your code here
Next x 'you next to add next x
End If
lstretri.ListIndex = x
txtCluburl.Text = lstretri.List(x)
lblcurrent.Caption = "Current: " & lstretri.ListIndex
-
May 9th, 2002, 02:10 PM
#11
Hyperactive Member
better yet write it like this
VB Code:
If Not Dir$((App.Path & "\" + strName)) = "" Then
intListBoxCount = Int(GetFromINI("Saved Values", "ListBox_Count", (App.Path & "\" + strName)))
Else
intListBoxCount = 0
End If
For x = intListBoxCount To lstretri.ListCount - 1
lstretri.ListIndex = x
txtCluburl.Text = lstretri.List(x)
lblcurrent.Caption = "Current: " & lstretri.ListIndex
Next x 'you next to add next x
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|