|
-
May 5th, 2003, 04:25 PM
#1
Thread Starter
Member
*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.
-
May 5th, 2003, 04:33 PM
#2
-= B u g S l a y e r =-
try using uppercase or lower case
If UCase(Name$) = UCase(str$)
maybe ?
-
May 5th, 2003, 04:36 PM
#3
Thread Starter
Member
No such luck... Trim either.
-
May 5th, 2003, 04:44 PM
#4
-= B u g S l a y e r =-
strange indeed...
I tried this
VB Code:
Private Sub Command1_Click()
Dim s1 As String
Dim s2 As String
Dim i As Integer
s1 = Text1(0).Text
For i = 1 To Text1.Count - 1
s2 = Text1(i).Text
If s1 = s2 Then MsgBox "Success": Exit For
MsgBox s1 & " " & s2
Next i
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 $
-
May 5th, 2003, 04:47 PM
#5
I got this to work:
VB Code:
Private Sub Command1_Click()
Dim prn As Printer
Dim str As String
For Each prn In Printers
str = prn.DeviceName
If str = "HP DeskJet 400" Then
MsgBox "Success"
Exit For
End If
MsgBox str
Next
End Sub
Rewrite your IF THEN statement.
Check your values for Name$
Try to use both Trim() and UCase(), Trim() first.
-
May 5th, 2003, 04:49 PM
#6
Thread Starter
Member
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?
-
May 5th, 2003, 07:41 PM
#7
-= B u g S l a y e r =-
-
May 5th, 2003, 07:43 PM
#8
-= B u g S l a y e r =-
huh?
it says resolved ? would you like to share the solution ?
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
|