Results 1 to 8 of 8

Thread: *RESOLVED * String Comparison Problem

  1. #1

    Thread Starter
    Member Eikon's Avatar
    Join Date
    Jan 2001
    Posts
    33

    *RESOLVED * String Comparison Problem

    I have stored the names of two printers in an INI using WritePrivateProfileString. I read them back into two strings using GetPrivateProfileString. I then want to set the printer to the name of one of those strings:

    Dim prn As Printer
    Dim str As String

    For Each prn In Printers
    str = prn.DeviceName
    If Name$ = str$ Then MsgBox "Success": Exit For
    MsgBox Name$
    MsgBox str$
    Next

    The problem is that both Name$ and String$ are exactly the same in the MsgBoxes but my success condition never fires. Do i need to do some special formating to get a loaded INI string to match a Printer DeviceName string?

    Solution:
    Ret$ = Space(255)
    Call GetPrivateProfileString("Printers", "FullPage", "", Ret$, 255, IniFile$)
    Ret$ = Left(Ret$, Len(Trim$(Ret)) - 1)
    fpPrinter$ = Ret$
    Last edited by Eikon; May 5th, 2003 at 06:14 PM.

  2. #2
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    try using uppercase or lower case

    If UCase(Name$) = UCase(str$)

    maybe ?
    -= a peet post =-

  3. #3

    Thread Starter
    Member Eikon's Avatar
    Join Date
    Jan 2001
    Posts
    33
    No such luck... Trim either.

  4. #4
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    strange indeed...

    I tried this

    VB Code:
    1. Private Sub Command1_Click()
    2.     Dim s1 As String
    3.     Dim s2 As String
    4.     Dim i As Integer
    5.     s1 = Text1(0).Text
    6.     For i = 1 To Text1.Count - 1
    7.         s2 = Text1(i).Text
    8.         If s1 = s2 Then MsgBox "Success": Exit For
    9.         MsgBox s1 & " " & s2
    10.     Next i
    11. End Sub

    worked as it should... only difference (assuming the strings in your code are the exact same) are the vars... maybe something about the usage of $

    -= a peet post =-

  5. #5
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629
    I got this to work:

    VB Code:
    1. Private Sub Command1_Click()
    2.    Dim prn As Printer
    3.    Dim str As String
    4.    
    5.    For Each prn In Printers
    6.       str = prn.DeviceName
    7.       If str = "HP DeskJet 400" Then
    8.          MsgBox "Success"
    9.          Exit For
    10.       End If
    11.       MsgBox str
    12.    Next
    13. End Sub

    Rewrite your IF THEN statement.
    Check your values for Name$
    Try to use both Trim() and UCase(), Trim() first.

  6. #6

    Thread Starter
    Member Eikon's Avatar
    Join Date
    Jan 2001
    Posts
    33
    Thats the thing though because I cant do checking like that. This must work on all machines for all printer names.

    My string has a "/" in it, should that matter?

  7. #7
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    tried using a "/" , still the sample I used above worked just fine...

    could you post the parts of the progject that do not work?
    -= a peet post =-

  8. #8
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    huh?

    it says resolved ? would you like to share the solution ?
    -= a peet post =-

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