TwelvestoneBack End

I think I may have done something stupid... (vb.net)


Sign in

  • Waiting for Godot ( 720 k posts )
    Just conversation.
  • Thunder Dome ( 23 k posts )
    Photoshop Tennis and Collabs.
  • Photography ( 4.8 k posts )
    For all you shutterbugs, sh...
  • Flash ( 18 k posts )
    ActionScripting to tweens, ...
  • Front End ( 5.8 k posts )
    general front end design an...
  • Back End ( 9.6 k posts )
    serverside scripting, progr...
  • Projects and Theory ( 12 k posts )
    This forum is for discussio...
  • FAQ ( 269 posts )
    All those nagging questions...
  • Design ( 17 k posts )
    graphics & all aspects of g...
  • Purgatory ( 3.6 k posts )
    12stone Jail, feel free to ...
JimmyTheGent
 
2010-03-16

I am working on an internal web app and the simplist little part of it isn't working. It is the most basic of basic validation checks and I just can't seem to spot the problem.

The application takes a keyword from the query string. an Example of this being "PurchaseTracker"

the code has been dumbed down to hell to try and debug...

MsgBox(dskb.validation.checkAlphaNumString("PurchaseTracker").ToString)

All this should do is show true in the msgbox. The validation code is here

Public Shared Function checkAlphaNumString(ByVal input As String) As Boolean 'check that input is not empty If input = "" Or input.Length < 1 Then Return False Exit Function End If Try

            'Validate 
            Dim AlphaNum As String = "^[a-zA-Z0-9]{1,20}$"  
            Dim checkstring As New Regex(AlphaNum, RegexOptions.IgnoreCase)
            Dim check As Match = checkstring.Match(input)
            If check.Success Then
                Return True 'matched OK
                Exit Function
            Else
                Return False
                Exit Function
            End If

        Catch ex As Exception
            Dim err As New dskb.Errors
            err.NewError(ex.Message & ex.ToString, "validation.vb - checkAlphaNumString", input)
        End Try
    End Function

As expected the string here returns true, however the msgbox shows false. Any ideas why? Doing my head in beign stuck on such a daft little thing. I have not done any code work in about 9 months so figured I am rusty and doing something stupid. k

Hideaway
 
2010-03-16

C# d00d, here...

This may seem silly, but can you put a break in the code file and step through the procedure? It MIGHT be a scope of when the method is called. Or I could be retarded.

And a side tiny note, does VB.NET have a String.Empty property and/or String.IsNullOrEmpty(someString) method? Just curious...

JimmyTheGent
 
2010-03-16

I have already went break point mad and stepped through it all. The validation comes out as true so skips to the "return true" part of the function.

But then whatever catches it from the main app, the above example is a msgbox as i was trying to figure it out. It changes to false for some reason. It is just really weird which is why I thought I did something daft.

in VB you can check if it = nothing. I know a little c# and know that it differs. Im sure there will be a string.isempty function too though.

Hideaway
 
2010-03-16

Can you put a break point in the main app? Or when you run your main app, can you step through this method as it's called from the main app?

My assumption is the main app isn't passing the correct string to the function. Without having any source, it's hard to say for sure.

Stmoo
 
2010-03-16

I've just ran your code and the MsgBox returns "True".

Create a test.aspx (with nothing other than a button) and test.aspx.vb file in your app with just the code:

Partial Class _Default Inherits System.Web.UI.Page

Public Shared Function checkAlphaNumString(ByVal input As String) As Boolean

    'check that input is not empty
    If input = "" Or input.Length < 1 Then
        Return False
        Exit Function
    End If

    Try
        'Validate 
        Dim AlphaNum As String = "^[a-zA-Z0-9]{1,20}$"
        Dim checkstring As New Regex(AlphaNum, RegexOptions.IgnoreCase)
        Dim check As Match = checkstring.Match(input)

        If check.Success Then
            Return True 'matched OK
            Exit Function
        Else
            Return False
            Exit Function
        End If

    Catch ex As Exception
        'Nothing for now
    End Try

End Function

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    MsgBox(checkAlphaNumString("PurchaseTracker").ToString)
End Sub

End Class

Check your namespaces are correct. Have you got another version of checkAlphaNumString kicking about in your solution?

JimmyTheGent
 
2010-03-16

The app is passing in the correct input, I checked that during a breakpoint but also passed in a string directly to test it.

JimmyTheGent
 
2010-03-16

I will check the namespaces, I never thought of that and I did steal my validation class from my previous project k

Stmoo
 
2010-03-16

Right click the method name and select "Go to definition". You may be surprised where you end up. k

JimmyTheGent
 
2010-03-17

I removed the imported validation class and created a new one, then just pasted the code for the above validation. It now returns True.

When i used the goto definition option it took me to the correct place, so why it was returning false I still don't really know. But recreating the class has done the trick anyway. I think it was probably name space related as suggested...

Many thanks for ideas on this one...I probably shouldn't have been lazy and imported that class when it only takes 2 secs to create one.

Sorry, you must be a member to post to a conversation. Either log in or sign up to get involved.
TwelvestoneBack End

I think I may have done something stupid... (vb.net)