PDA

View Full Version : Solved: If Question



slamet Harto
03-13-2009, 02:47 AM
Hi there,

can you advise what i'm wrong with this line.


Dim SetSvr As String
Sheets("MainData").Range("A1").Value = ""
SetSvr = InputBox("Please Entry IP Address to connecting or Call your Administrator", "Invalid IP Address")


If Len(Trim(SetSvr)) = 0 Then End
If Len(Trim(SetSvr)) = "" Then
MsgBox "You entered nothing", vbCritical, "Warning"

Range("A1").Value = "You entered nothing"
StartBlink
'End
Else
If Len(Trim(SetSvr)) <> "

slamet Harto
03-13-2009, 03:04 AM
My apologize. bad connection I guess.
Please ignore my prev thread.

Dim SetSvr As String
'Sheets("MainData").Range("A1").Value = ""
SetSvr = InputBox("Please Entry IP Address to connecting or Call your Administrator", "Invalid IP Address")


'If Len(Trim(SetSvr)) = 0 Then End
'If Len(Trim(SetSvr)) > 0 Then
'Else
If Len(Trim(SetSvr)) = "" Then
MsgBox "You entered nothing", vbCritical, "Warning"

Range("A1").Value = "You entered nothing"
StartBlink
'End
Else
If Len(Trim(SetSvr)) <> "H:\MY\CTC\" & _
'"DBase\Master.mdb" Then

MsgBox "Invalid IP Address", vbCritical, "Warning"
Range("A1").Value = "Invalid IP Address, please enter new IP"
'StartBlink
Else
SuppRegister "server.ini", "SERVER=" & Trim(SetSvr)
StopBlink
Sheets("MainData").Range("A1").Value = ""
LoginForm.Show
'End If
End If
End If

Bob Phillips
03-13-2009, 03:15 AM
Is this still a problem? You have an If statement with a continuation lien, but the next line is commen ted out.

slamet Harto
03-13-2009, 04:16 AM
I'm stuck, can't figure out

Please help

Thank you so much

Bob Phillips
03-13-2009, 04:42 AM
Can't figure what though?

slamet Harto
03-13-2009, 05:08 AM
Bob,

just trying to make it clear, can you help to fix for the following code:

Private Sub CommandButton1_Click()
Dim Asking As String

Asking = InputBox("Please Entry SOMETHING", "INPUT")

If Len(Trim(Asking)) = 0 Then
MsgBox "You entered nothing", vbCritical, "Warning"

Range("A1").Value = "You entered nothing"
ElseIf Not Len(Trim(Asking)) = "AB" Then
MsgBox "Invalid", vbCritical, "Warning"

Range("A1").Value = "Invalid!!"

End If
If Len(Trim(Asking)) = "AB" Then
MsgBox "You are Luck", vbCritical, "WELCOME"

Range("A1").Value = ""

End If
End Sub

thanks for assistance

Simon Lloyd
03-13-2009, 05:29 AM
The problem is with your LEN statement, LEN is looking for a numerical value not a string! if you changed it to be ElseIf Not Len(Trim(Asking)) > 0 Then...etc then it will work fine, or you have to lose the LEN!

mdmackillop
03-13-2009, 05:36 AM
Rather than multiple Ifs, try using a Select Case routine

Private Sub CommandButton1_Click()
Dim Asking As String
Asking = InputBox("Please Entry SOMETHING", "INPUT")
Select Case Trim(Asking)
Case ""
MsgBox "You entered nothing", vbCritical, "Warning"
Case "AB"
MsgBox "You are Luck", vbCritical, "WELCOME"
Range("A1").Value = ""
Case Else
MsgBox "Invalid", vbCritical, "Warning"
Range("A1").Value = "Invalid!!"
End Select
End Sub

Bob Phillips
03-13-2009, 05:36 AM
Private Sub CommandButton1_Click()
Dim Asking As String

Asking = InputBox("Please Entry SOMETHING", "INPUT")

If Len(Trim(Asking)) = 0 Then
MsgBox "You entered nothing", vbCritical, "Warning"

Range("A1").Value = "You entered nothing"
ElseIf Trim(Asking) <> "AB" Then
MsgBox "Invalid", vbCritical, "Warning"

Range("A1").Value = "Invalid!!"

Else
MsgBox "You are Luck", vbCritical, "WELCOME"

Range("A1").Value = ""

End If
End Sub

Bob Phillips
03-13-2009, 05:37 AM
Actually, why bother with the Len test



Private Sub CommandButton1_Click()
Dim Asking As String

Asking = InputBox("Please Entry SOMETHING", "INPUT")

If Trim(Asking) <> "AB" Then
MsgBox "Invalid", vbCritical, "Warning"

Range("A1").Value = "Invalid!!"

Else
MsgBox "You are Luck", vbCritical, "WELCOME"

Range("A1").Value = ""

End If
End Sub

Simon Lloyd
03-13-2009, 05:38 AM
Bob, does this line ElseIf Trim(Asking) <> "AB" Then work?, i initially did that but it still fails :)

Simon Lloyd
03-13-2009, 05:39 AM
Lol, ooops sorry i didnt read it properly....the LEN has gone!

Bob Phillips
03-13-2009, 05:40 AM
Yes, it does for me no problems. It is just testing for a string.

Simon Lloyd
03-13-2009, 05:56 AM
Yeah i noticed, apology in previous post! :)

slamet Harto
03-13-2009, 06:05 AM
Wonderful world, thank you for great support.

God bless you