Valhalla Legends Forums Archive | Visual Basic Programming | Argument Not Optional

AuthorMessageTime
Dyndrilliac
What does this mean? I got it recently when writing a small database app.

[code]Open "Users.dat" For Append As #1
Close #1
Open "Pass.dat" For Append As #1
Close #1
cboUser.List = GetStuff("Users", "", "")[/code]

Is what errors and my function for GetStuff is globally declared as:

[code]Function GetStuff(FileName As String, appname As String, key As String) As String
Dim sFile As String
Dim sDefault As String
Dim lSize As Integer
Dim l As Long
Dim sUser As String
sUser = Space$(128)
lSize = Len(sUser)
sFile = App.Path & "\" & FileName & ".dat"
sDefault = ""
l = GetPrivateProfileString(appname, key, sDefault, sUser, lSize, sFile)
sUser = Mid(sUser, 1, InStr(sUser, Chr(0)) - 1)
GetStuff = sUser
End Function[/code]

Can anyone tell me what's wrong?
November 13, 2003, 3:13 PM
Adron
[quote author=Dyndrilliac link=board=31;threadid=3581;start=0#msg28984 date=1068736411]
What does this mean? I got it recently when writing a small database app.

[code]cboUser.List = GetStuff("Users", "", "")[/code]
[/quote]

I'm thinking you probably need to pass an index to List?
November 13, 2003, 5:48 PM
______
[quote author=Dyndrilliac link=board=31;threadid=3581;start=0#msg28984 date=1068736411]
[code]
cboUser.List = GetStuff("Users", "", "")[/code]

[/quote]

Why not try

[code]
cboUser.additem GetStuff("Users", "", "")
[/code]
November 13, 2003, 5:59 PM
Dyndrilliac
[quote author=Adron link=board=31;threadid=3581;start=0#msg28995 date=1068745684]
I'm thinking you probably need to pass an index to List?
[/quote]Erm, explain?.

Btw - I still error with .AddItem
November 14, 2003, 2:24 PM
Adron
[quote author=Dyndrilliac link=board=31;threadid=3581;start=0#msg29119 date=1068819853]
[quote author=Adron link=board=31;threadid=3581;start=0#msg28995 date=1068745684]
I'm thinking you probably need to pass an index to List?
[/quote]Erm, explain?.

Btw - I still error with .AddItem
[/quote]

I don't know, but for the lists I use, List is typically an array, and you need to do something like List(0) = "bla bla"... But, then you need to have added an item already, so the best answer for you is probably to use some method that adds an item.
November 14, 2003, 5:13 PM
Grok
Sounds like he's probably confused over the differences in .List and .AddItem. Typically you use AddItem to append a new item to the ComboBox. Use .List(index) to read or modify an existing entry in the ComboBox.

If you want to read or modify the currently-selected item, you can use .Text property.
Some more examples:

[code]
cboUsers.AddItem "[vL]Adron" 'adds a user to the combo's list
cboUsers.ListIndex = 0 'selects the first entry in the combo's list
cboUsers.Text = "[vL]Grok" 'changes selected user name
cboUsers.RemoveItem 5 'removes the 6th entry in the list
cboUsers.List(3) = "[vL]Skywing" 'changes user name of 4th entry in list
MsgBox cboUsers.List(0) 'displays user in combo list first slot
[/code]

Hope this helps.
November 14, 2003, 8:44 PM
Dyndrilliac
Well, I tried[code]cboUser.additem GetStuff("Users", "", "")[/code]ad it didn't work - any others that Add Items without there already being an item?
November 14, 2003, 11:41 PM
Stealth
Couple questions. Why are you opening the files for Append, then immediately closing them? As far as I know this has no effect whatsoever.

Secondly, has users.dat already been created so that GetStuff() can retrieve information from it? Why don't you test GetStuff()'s output by adding

[code]
Debug.Print GetStuff("Users", "", "")
[/code]

to make sure that you're getting what you want in the first place? Your .additem code is correct as far as adding items to the combobox is concerned.
November 15, 2003, 8:13 AM
Grok
[quote author=Dyndrilliac link=board=31;threadid=3581;start=0#msg29192 date=1068853312]
Well, I tried[code]cboUser.additem GetStuff("Users", "", "")[/code]ad it didn't work - any others that Add Items without there already being an item?
[/quote]

You do realize that GetStuff("users", "", "") will always return an empty string?

[code]
Private Sub Command1_Click()
cboUser.AddItem GetStuff("Users", "names", "1")
cboUser.ListIndex = cboUser.ListCount - 1
End Sub

Private Function GetStuff(FileName As String, appname As String, key As String) As String

Dim sFile As String
Dim sDefault As String
Dim lSize As Integer
Dim l As Long
Dim sUser As String

sUser = Space$(128)
lSize = Len(sUser)
sFile = App.Path & "\" & FileName & ".dat"
sDefault = ""
l = GetPrivateProfileString(appname, key, sDefault, sUser, lSize, sFile)
sUser = Mid(sUser, 1, InStr(sUser, Chr(0)) - 1)
GetStuff = sUser

End Function
[/code]
November 15, 2003, 3:41 PM
Dyndrilliac
[quote author=Stealth link=board=31;threadid=3581;start=0#msg29252 date=1068883997]
Couple questions. Why are you opening the files for Append, then immediately closing them? As far as I know this has no effect whatsoever.

Secondly, has users.dat already been created so that GetStuff() can retrieve information from it? Why don't you test GetStuff()'s output by adding

[code]
Debug.Print GetStuff("Users", "", "")
[/code]

to make sure that you're getting what you want in the first place? Your .additem code is correct as far as adding items to the combobox is concerned.
[/quote]

Well for one, My idea that was the Append would create the file if it didn't already exist, but I did make sure it does.

Grok, dont mean to sound ignorant, but um, what? I wasn't thinking in terms of string, i just reasoned that since the users.dat has the user names, the combobox should get it's list from there...
November 15, 2003, 5:17 PM
Grok
The combo box will just sit on your form until you tell it otherwise. If you want to add items to the list, you must add each string using the AddItem method of the ComboBox.

To do that, you need to iterate through your keys using GetPrivateProfileString, (or GetPrivateProfileSection, then split that into an array and walk through it), adding each value as the new string item.

For this to work, GetPrivateProfileString (or Section) expects an INI-style textfile, as such:

[names]
name1=[vL]Grok
name2=[vL]Adron
name3=[vL]Skywing

To get the value of 'name2', you'd do this:

[code]
key = "name2"
l = GetPrivateProfileString(appname, key, sDefault, sUser, lSize, sFile)
[/code]
November 15, 2003, 8:30 PM
Adron
Isn't there some way to have GetPrivateProfileString return a list of all the value names found in a section, or all the sections found in an ini file? Passing in null or something like that?
November 16, 2003, 12:33 AM
Grok
[quote author=Adron link=board=31;threadid=3581;start=0#msg29367 date=1068942796]
Isn't there some way to have GetPrivateProfileString return a list of all the value names found in a section, or all the sections found in an ini file? Passing in null or something like that?
[/quote]

Not that I'm aware of, did you see it in MSDN? AFAIK, you use GetPrivateProfileSection for that.
November 16, 2003, 1:06 AM
Adron
[quote author=Grok link=board=31;threadid=3581;start=0#msg29380 date=1068944772]
Not that I'm aware of, did you see it in MSDN? AFAIK, you use GetPrivateProfileSection for that.
[/quote]

Hmm, no, it was just a vague memory I had. I haven't used those functions in a long time.

edit:
MSDN says:
[quote]
DWORD GetPrivateProfileString(
LPCTSTR lpAppName, // section name
LPCTSTR lpKeyName, // key name
LPCTSTR lpDefault, // default string
LPTSTR lpReturnedString, // destination buffer
DWORD nSize, // size of destination buffer
LPCTSTR lpFileName // initialization file name
);

Parameters

lpAppName

[in] Pointer to a null-terminated string that specifies the name of the section containing the key name. If this parameter is NULL, the GetPrivateProfileString function copies all section names in the file to the supplied buffer.

lpKeyName

[in] Pointer to the null-terminated string specifying the name of the key whose associated string is to be retrieved. If this parameter is NULL, all key names in the section specified by the lpAppName parameter are copied to the buffer specified by the lpReturnedString parameter.

[/quote]
November 16, 2003, 1:20 AM
Grok
Ah, makes sense. I wrote an INI class that has a GetSection() method which takes advantage of that feature.
November 16, 2003, 2:50 AM
MrRaza
I used to work with INI-File type functions alot. I'll post some of my old code, if i can find it.
November 16, 2003, 5:49 AM
Adron
[quote author=Grok link=board=31;threadid=3581;start=0#msg29399 date=1068951031]
Ah, makes sense. I wrote an INI class that has a GetSection() method which takes advantage of that feature.
[/quote]

I was thinking maybe the original poster was confused about that, thinking that if he passed in empty strings, he'd get everything. And that assigning it to List would automagically parse it out for him.
November 16, 2003, 1:09 PM
Dyndrilliac
[quote author=Adron link=board=31;threadid=3581;start=15#msg29462 date=1068988166]
[quote author=Grok link=board=31;threadid=3581;start=0#msg29399 date=1068951031]
Ah, makes sense. I wrote an INI class that has a GetSection() method which takes advantage of that feature.
[/quote]

I was thinking maybe the original poster was confused about that, thinking that if he passed in empty strings, he'd get everything. And that assigning it to List would automagically parse it out for him.
[/quote]
That was my original intention - I wanted to pick a file to tretrieve all the data from so i could have unlimited usernames and compare the username they chose with the password on the same line of the other file that would hold the passwords.
November 20, 2003, 7:45 PM

Search