|
-
Dec 1st, 2003, 12:11 PM
#1
Thread Starter
Addicted Member
[SOLVED]"Variable not defined" error
I've set the variable "WhichFav" to the Index of a control, and when i execute this:
VB Code:
Call saveini("favorites", WhichFav)
I get error saying: "Variable not defined" in the function saveini().
Contents of saveini():
VB Code:
Private Function saveini(KeySection As String, KeyKey As String)
Dim lngResult As Long
Dim strFileName
strFileName = App.Path & "\options.ini"
lngResult = WritePrivateProfileString(KeySection, _
KeyKey, KeyValue, strFileName)
If lngResult = 0 Then
'An error has occurred
Call MsgBox("An error has occurred while saving the options", vbExclamation)
End If
KeyValue = Trim(strResult)
End Function
What is wrong?
Could it be that WhichFav is an integer?
I've tried CStr(WhichFav) but that doesn't work either, same error
Last edited by vigge89; Dec 1st, 2003 at 01:19 PM.
-
Dec 1st, 2003, 12:23 PM
#2
Which line does VB break on?
Where is KeyValue declared?
-
Dec 1st, 2003, 12:26 PM
#3
Thread Starter
Addicted Member
KeyValue is declared at top, so it's global.
VB breaks at "KeyValue = Trim(strResult)"
Where strResult is the undefined variable.
It have worked before, but when I used WhichFav, it didn't work
-
Dec 1st, 2003, 12:34 PM
#4
And where is strResult declared?
-
Dec 1st, 2003, 12:36 PM
#5
Thread Starter
Addicted Member
nowhere?
i don't know it worked before, but i'll test with declaring it as string
-
Dec 1st, 2003, 12:40 PM
#6
Thread Starter
Addicted Member
yep works now, declared the strResult as string (Dim strResult As String * 50)
and added some stuff in
VB Code:
Private Sub mnuFavSet_Click()
lblFavColor(WhichFav).BackColor = lColor
KeyValue = lColor 'Added this, forgot it before (this makes the function write anything at all :P )
Call saveini("favorites", WhichFav)
End Sub
-
Dec 1st, 2003, 12:44 PM
#7
Originally posted by vigge89
KeyValue is declared at top, so it's global.
VB breaks at "KeyValue = Trim(strResult)"
Where strResult is the undefined variable.
It have worked before, but when I used WhichFav, it didn't work
Unless strResult is defined somewhere within the scope of the function it will be "undefined".
BTW, why is saveini a function since you are not returning anything from it.
-
Dec 1st, 2003, 12:57 PM
#8
Thread Starter
Addicted Member
Originally posted by MartinLiss
Unless strResult is defined somewhere within the scope of the function it will be "undefined".
BTW, why is saveini a function since you are not returning anything from it.
since i don't know how to make the function return anything, i use a global variable to store its results
also, i know that it has to be defined, but it worked when i used Saveini("favorites", lblSomecolor.Backcolor)
Last edited by vigge89; Dec 1st, 2003 at 01:10 PM.
-
Dec 1st, 2003, 01:00 PM
#9
What do you want it to return? The following returns the result of the Trim function.
VB Code:
Private Function saveini(KeySection As String, KeyKey As String) [color="#0000FF"]As String[/color]
Dim lngResult As Long
Dim strFileName
strFileName = App.Path & "\options.ini"
lngResult = WritePrivateProfileString(KeySection, _
KeyKey, KeyValue, strFileName)
If lngResult = 0 Then
'An error has occurred
Call MsgBox("An error has occurred while saving the options", vbExclamation)
End If
[color="#FF00FF"]saveini [/color]= Trim(strResult)
End Function
-
Dec 1st, 2003, 01:13 PM
#10
Thread Starter
Addicted Member
ok, great that was exactly what i wanted
-
Dec 1st, 2003, 01:18 PM
#11
strResult still needs to be defined someplace. Do you mean lngResult?
-
Dec 1st, 2003, 01:20 PM
#12
Thread Starter
Addicted Member
I've already defined strResult as string!
-
Dec 1st, 2003, 01:54 PM
#13
Thread Starter
Addicted Member
New question:
How do u convert a string into number?
I've saved the xpos and ypos of a form in INI file, but when i retrieve them, i get type missmatch. Code:
VB Code:
Me.Left = Int(loadini("settings", "xpos"))
Me.Top = Int(loadini("settings", "ypos"))
I've tested with, and without the Int(), but it won't work
-
Dec 1st, 2003, 01:56 PM
#14
Thread Starter
Addicted Member
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
|