varibale trouble.

ident

Newcomer
Joined
May 29, 2008
Messages
5
basically here is my issue. I run a football team and i pay o2 for online texts each month so i can send weekly texts to are team to let them know this weeks game details.

Right i do this by sendkeys, which is not a issue. But the issue is i want it to be able to only send a sertain number of times. at the moment it goes on indef. which is never good.

I'l just point out im a complete beginer with vb.net, and only code for fun. It only takes me ten minutes to send the messages manually but i wanted to do it just for fun.

2 of the text boxes, txtN.text = number of times to send & txtH.text is the hidden text box that stores the varible. i dont know how else i could use a varible out of the sub? like i said im a beginner im sure there are better ways.


this is what happens when send is clicked, i loop through the whole thing on timers :/

this timers interval is 8 seconds to avoid flooding(as are both timers)
Code:
    Private Sub Timer2_Tick_2(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
 dim x,n
x = txtN.text
n = 1

txtH.txt = n

if n < x then
n = n +1
        'send keys commands are here
        Timer2.Enabled = False
        Timer3.Enabled = True
txtH.txt = n
else
timer2.enabled = false
timer3.enabled = false
end if

    End Sub

    Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
        Dim ID

        ID = txtID.Text

        Dim web As System.Uri = New System.Uri("urlhere" & ID)
        Me.WebBrowser1.Navigate(web)
        Timer3.Enabled = False
        Timer2.Enabled = True


    End Sub

yes im sure some of you are laughing at my code. this is probably such a poor way to do it. im only doing it to learn and i enjoy it.

the error i get is something like i cant use a varible as a interger and a string?

i only written this off of the top of my head, at a different pc but wanted to get the ball rolling with some help.

any advice very much welcome,

thanks
 
Everyone has to start somewhere so I really wouldn't worry about it.

Regarding the difference between integers and strings - you will need to convert the values something like the following should work
Visual Basic:
Private Sub Timer2_Tick_2(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        Dim x As Integer = Integer.Parse(txtN.Text)
        Dim n As Integer = 1

        txtH.Text = n.ToString

        If n < x Then
            n = n + 1
            'send keys commands are here
            Timer2.Enabled = False
            Timer3.Enabled = True
            txtH.Text = n.ToString
        Else
            Timer2.Enabled = False
            Timer3.Enabled = False
        End If

    End Sub

    Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
        Dim ID As Integer = Integer.Parse(txtID.Text)

        Dim web As System.Uri = New System.Uri("urlhere" & ID.ToString())
        Me.WebBrowser1.Navigate(web)
        Timer3.Enabled = False
        Timer2.Enabled = True
    End Sub

If you need to access a variable from more than one routine you can declare it at the form (or class) level - this means it should be available to any routine in the same form (or class).
Visual Basic:
Private _number As Integer
    Private Sub Timer2_Tick_2(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        Dim x As Integer = Integer.Parse(txtN.Text)
        Dim n As Integer = 1

        _number = n

        If n < x Then
            n = n + 1
            'send keys commands are here
            Timer2.Enabled = False
            Timer3.Enabled = True
            _number = n
        Else
            Timer2.Enabled = False
            Timer3.Enabled = False
        End If

    End Sub

    Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
        Dim ID As Integer = Integer.Parse(txtID.Text)

        Dim web As System.Uri = New System.Uri("urlhere" & ID.ToString())
        Me.WebBrowser1.Navigate(web)
        Timer3.Enabled = False
        Timer2.Enabled = True
    End Sub

You could potentially remove an unneeded variable this way giving something like...
Visual Basic:
Private _number As Integer
    Private Sub Timer2_Tick_2(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        Dim x As Integer = Integer.Parse(txtN.Text)

        _number = 1

        If _number < x Then
            _number = _number + 1
            'send keys commands are here
            Timer2.Enabled = False
            Timer3.Enabled = True
        Else
            Timer2.Enabled = False
            Timer3.Enabled = False
        End If

    End Sub

    Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
        Dim ID As Integer = Integer.Parse(txtID.Text)

        Dim web As System.Uri = New System.Uri("urlhere" & ID.ToString())
        Me.WebBrowser1.Navigate(web)
        Timer3.Enabled = False
        Timer2.Enabled = True
    End Sub
 
Back
Top