Results 1 to 8 of 8

Thread: can't get rid of that line...

  1. #1
    bzemer
    Guest

    Angry 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...

  2. #2
    Junior Member
    Join Date
    Jun 2001
    Location
    Redcar, UK
    Posts
    24
    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."

  3. #3
    Addicted Member Screamager's Avatar
    Join Date
    May 2001
    Location
    Dublin, Ireland
    Posts
    174
    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

  4. #4
    bzemer
    Guest

    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

  5. #5
    bzemer
    Guest

    <>

    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...

  6. #6
    Addicted Member stevess's Avatar
    Join Date
    May 2001
    Posts
    251
    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.

  7. #7
    Addicted Member stevess's Avatar
    Join Date
    May 2001
    Posts
    251
    Actually, at the end of nget you should do
    NGwhom = TrimCString(TxtStr)

  8. #8
    bzemer
    Guest

    Thumbs up 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
  •  



Click Here to Expand Forum to Full Width