|
-
January 18th, 2004, 09:37 AM
#1
Writing data from txt file..Help!
Hi,
I have a text file with data similar to this:
[List1]
Item1
Item2
Item3
[List2]
Item1
[List3]
Item 1
Item 2
Item 3
Item 4
Item 5
Etc...
I have a command button and a number of Labels on my form form, Lbl1, Lbl2,etc.
I want to click button and input box to come up, then if you type list1 all items under list 1 in txt file go to labels, but stops at last item in list.
If there is only a few items in a list, i dont want all labels to be used, only as required.
Any info on this?
Thanks
Mark.
-
January 18th, 2004, 09:54 AM
#2
You can dinamically load labels. Create an only invisible label with its index property to 0. Then, for each line in the txt:
Dim intCount as Integer
intCount = Label1.Count
Load Label1(intCount)
Label1(intCount-1).Left = Label1(intCount-2).Left
Label1(intCount-1).Top = Label1(intCount-2).Top + 200
Label1(intCount-1).Visible = True
Label1(intCount-1).Caption = line data
Before you unload the form, you do:
Dim intIndex as Integer
For intIndex = 1 To intCount-1
Unload Label1(intIndex)
Next
-
January 18th, 2004, 10:15 AM
#3
Hi,
Thanks for the reply. But how do i get the data in from the text file, for the list which is selected in input box?
Mark
-
January 18th, 2004, 04:56 PM
#4
Seeing as your text file is formatted like an ini file, you can use "GetPrivateProfileString" as follows:
Code:
Option Explicit
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
' Globals - we might be able to re-use some of this stuff
Public gsRetFile As String
Public gsDBServer As String
Public gsDatabaseName As String
Public Function GetIniSettings() As Boolean
'
On Error GoTo ErrTrap
Dim ret As Long
Dim nSize As Integer
Dim tmpString As String * 128
' Retrieve all the ini settings from the ini file
gsRetFile = App.Path & "\" & App.EXEName & ".ini"
tmpString = ""
' DatabaseName
gsDatabaseName = ""
lpAppName = "Database Settings"
lpKeyName = "DatabaseName"
lpDefault = "Unknown"
lpFileName = gsRetFile
ret = GetPrivateProfileString(lpAppName, lpKeyName, lpDefault, tmpString, Len(tmpString), lpFileName)
gsDatabaseName = Left(tmpString, ret)
tmpString = ""
GetIniSettings = True
End Function
Be nice to Harley riders...
-
January 18th, 2004, 05:24 PM
#5
Hi, thanks for the reply.
I am not using database though, this code is for a game i am making :-)
Also, how would I include the InputBox bit to say which list I want?
Thanks
Mark
-
January 18th, 2004, 07:29 PM
#6
Doesn't matter whether you're using a database or not. That's just the section I wanted to get out of the text file.
Here's the format of my text file - putting this and my last post together, you should be able to figure out how to read from a text file in the .ini format
As you will see, the following line corresponds to the Section in the ini file that I'm after
Code:
lpAppName = "Database Settings"
and the following line corresponds to the LINE in the above Section that I'm after
Code:
lpKeyName = "DatabaseName"
[Database Settings]
ODBC=FALSE
DBServer=DevSQL
DatabaseName=Sales2000Test
UserName=Sa
Password=
ProgUser=bairdn
DeleteOnCompletion=True
TableName=tblContainerActivityNow
DBTimeOut=45
Be nice to Harley riders...
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
|