|
-
Jun 3rd, 2001, 08:05 AM
#1
can't get rid of that line...
Hi,
i have a piece of code that i use to read a line from an ini file but i want to find out if it's a line that i don't want to read and i can't do this for some reason. here is the code:
Code:
Private Sub Command1_Click
Dim TxtStr As String
Nget IniLine, "Text", TxtStr ' i'll explain down
If TxtStr = "unwanted" Then Exit Sub
Select Case TxtStr
Case Is = "unwanted"
Exit Sub
Case Is = ""
Exit Sub
Case Else
Text1.Text = TxtStr
End Select
End Sub
'Nget' is a function i use to read ini files.
As you can see i have put 2 forms of detection to see if TxtStr is "unwanted".
This code ignor the "unwated" text and display it anyway.
It also displays any other text, but thats what it's supposed to do.
Can anyone tell me what am i doing wrong..?
thanks...
-
Jun 3rd, 2001, 08:11 AM
#2
Junior Member
You would be better off posting the Nget code instead, thats where the string is being returned from the file.
"Three minutes thought would suffice to find this out; but thought is irksome and three minutes is a long time."
"The supreme irony of life is that hardly anyone gets out of it alive."
-
Jun 3rd, 2001, 08:12 AM
#3
Addicted Member
Code:
Select Case TxtStr
Case "unwanted"
Exit Sub
Case ""
Exit Sub
Case Else
Text1.Text = TxtStr
End Select
Computer /nm./: a device designed to speed and automate errors
-
Jun 3rd, 2001, 08:14 AM
#4
nget
here is the nget code:
Code:
Function Nget(NGtitle As String, NGstring As String, NGwhom As String)
Dim SIniFile
Dim lngResult As Long
Dim strResult As String * 50
SIniFile = App.Path & "\appini.ini"
lngResult = GetPrivateProfileString(NGtitle, NGstring, SIniFile, strResult, Len(strResult), SIniFile)
NGwhom = Trim(strResult)
End Function
-
Jun 3rd, 2001, 08:19 AM
#5
<>
Screamager
I tried it your way, it doesn't work.
i also tried something like this..:
i defined the value of 'Text' in the ini file to 'OK', and then i made 'TxtStr = Left(TxtStr,2)' which only took the first 2 letters.
These letters were 'OK' and the code worked. The problem is that i can't tell how long the user is going to make the 'Text' value in the ini file... so i need to find out how to make this code work...
-
Jun 3rd, 2001, 05:28 PM
#6
Addicted Member
The problem is that the string returned from nget is still 50 characters long. Trim does not remove Null characters (or ASCII zeros)
Add this Function
Function TrimCString(sStr As String) As String
Dim i As Integer
i = InStr(sStr, Chr$(0))
Select Case i
Case 0
TrimCString = sStr
Case 1
TrimCString = QQ
Case Else
TrimCString = Left$(sStr, i - 1)
End Select
End Function
Note: QQ is constant for ""
Then do
Select Case TrimCString(TxtStr)
Last edited by stevess; Jun 3rd, 2001 at 05:32 PM.
-
Jun 3rd, 2001, 05:29 PM
#7
Addicted Member
Actually, at the end of nget you should do
NGwhom = TrimCString(TxtStr)
-
Jun 4th, 2001, 08:45 AM
#8
thanks!!
It's working now thanks..!!
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
|