Results 1 to 10 of 10

Thread: file name verification problems

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2002
    Location
    Leeds, England
    Posts
    85

    file name verification problems

    Hi,

    I hope someone can help me Please!

    Here's what i want to do - from my VB appln when a user selects a file from the file browser in the vb appln, it takes the filename which should be in the format : -
    (4 digits-2digits-1or2digits-alphabet) e.g. 1111-20-1-a.dwg

    It then checks whether the filename is in the correct format

    If not it does this(...) else

    it takes the filename and puts it in a textbox BUT WITHOUT THE file extension (e.g. 1111-20-1-a gets entered into text box)

    areas in which I am having a problem is basically
    1) performing the check on the filename and
    2) which is related to the first one is getting the filename into a textbox without the file extension.

    Any help would be much appreciated

    Regards
    Eb

  2. #2
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    2
    VB Code:
    1. Temp = Mid(filename, InStrRev(filename, "\") + 1)
    2.  Temp = Mid(Temp, 1, Len(Temp) - 4)


    Has someone helped you? Then you can Rate their helpful post.

  3. #3
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    1) You can use the Mid() function to check each letter of what you get in my post above and check with the IsNumeric() or the ascii values if it is a number or not. You'll have to use the ascii to check if it is a "-".


    Has someone helped you? Then you can Rate their helpful post.

  4. #4
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    Here is a simple example. You'll still need to check i if the "-" are in the right positions.

    VB Code:
    1. Option Explicit
    2. Dim Filename As String
    3. Dim Temp As String
    4. Dim i As Integer
    5.  
    6. Private Sub Form_Load()
    7.  Filename = InputBox("Enter filename", "Enter filename")
    8.  Temp = Mid(Filename, InStrRev(Filename, "\") + 1)
    9.  Temp = Mid(Temp, 1, Len(Temp) - 4)
    10.  For i = 1 To Len(Temp)
    11.   If IsNumeric(Mid(Temp, i, 1)) = False And Asc(Mid(Temp, i, 1)) <> 45 Then
    12.    MsgBox "Invalid filename"
    13.    Exit Sub
    14.   End If
    15.  Next
    16. End Sub


    Has someone helped you? Then you can Rate their helpful post.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Nov 2002
    Location
    Leeds, England
    Posts
    85
    with your example : -
    Temp = Mid(Filename, InStrRev(Filename, "\") + 1)
    Temp = Mid(Temp, 1, Len(Temp) - 4)

    will that only chck the first 4 values of the filename
    Then if that succeeds I have to check "-" then the next 2 digits

    and so on ????

  6. #6
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    Originally posted by ebma1
    with your example : -
    Temp = Mid(Filename, InStrRev(Filename, "\") + 1)
    Temp = Mid(Temp, 1, Len(Temp) - 4)

    will that only chck the first 4 values of the filename
    Then if that succeeds I have to check "-" then the next 2 digits

    and so on ????
    No, the code above will get you the filename without the extention (specifically if it is 3 digits long but you could do it independant from that).


    Has someone helped you? Then you can Rate their helpful post.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Nov 2002
    Location
    Leeds, England
    Posts
    85
    Ok that works BUT how do i check for AlphaNumeric values

    The way I have done it is : -

    If (Mid(Temp, 6, 2)) Like "[A-Z]" = False And IsNumeric(Mid(Temp, 6, 2)) = False Then
    MsgBox "Invalid filename - error in SFB number"
    Exit Sub
    End If

    Is there a function that checks whether the value is a integer or a letter???

    PS: I am using VB6 SP5 because I think VB.NET has function called IsAlphaNumeric but VB6 doesn't

  8. #8
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    You need to check the ascii values :

    A=65
    B=66
    .
    .
    .
    Z=90

    a=97
    b=98
    .
    .
    .
    z=122

    Check if it is smaller or bigger these values...


    Has someone helped you? Then you can Rate their helpful post.

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Nov 2002
    Location
    Leeds, England
    Posts
    85
    Thank you very much for your help
    -I have sorted it out now!!!!

  10. #10
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    Anytime


    Has someone helped you? Then you can Rate their helpful 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