Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Short VB code error

  • 22-02-2005 2:08pm
    #1
    Moderators, Music Moderators, Recreation & Hobbies Moderators Posts: 9,390 Mod ✭✭✭✭


    Can anyone notice anything wrong with below
    thanks

    Option Explicit
    Private Sub Form_Load()
    Dim string1 As String
    Dim string2 As String
    Dim msg As String
    Dim position As Integer

    string1 = "smithtwitdumfreemantwitdumrothtwitdum"
    position = InStr(string1, "twitdum")
    string2 = Mid(string1, "twitdum")
    msg = "the first occurrence of " & "`" & string2 & "`"
    msg = msg & " is at position " & position
    msg = msg & vbCrLf & vbCrLf

    position = InStr(position + 1, string1, "twitdum")
    string2 = Mid(string1, position, 7)
    msg = msg & "the second occurrence of" & _
    "`" & string2 & "`"
    msg = msg & " is at postion " & position
    msg = msg & vbCrLf & vbCrLf

    position = InStr(position + 1, string1, "twitdum")
    msg = msg & " the third occurrence of " & _
    "`" & string2 & "`"
    msg = msg & " is at postion " & position
    MsgBox msg
    End Sub


Comments

  • Closed Accounts Posts: 2,639 ✭✭✭Laguna


    What's the error number/message you get during compile time?


  • Registered Users, Registered Users 2 Posts: 450 ✭✭krinpit


    Perhaps your problem is
    string2 = Mid(string1, "twitdum")
    
    Isn't the second parameter to Mid supposed to be an Integer?


  • Registered Users, Registered Users 2 Posts: 21,263 ✭✭✭✭Eoin


    Off the top of my head, it looks like you have the "mid" bit wrong. If the usage is the same as in ASP, which I would think it is, it expects the following syntax:
    string2 = mid(string1, nStart, nEnd)
    
    where nStart is the integer you want it to start at, and nEnd is the last position.

    You have passed in two strings instead of one string and two integers
    string2 = Mid(string1, "twitdum")

    Try this:
    string2 = mid(string1, instr(string1, "twitdum"), len("twitdum"))
    

    Eoin


Advertisement