VB.NET 2010 Web Request Refresh - vb.net

Hey im kind of new to VB and am trying to get a web request to refresh every 30 seconds, and have got stuck on how to implement a timer in to it. Here is the code I have produced so far, i would be grateful for the correct solution:
Public Class main
Dim boatid As Integer
Sub googlemaps()
Dim url As String = "http://www.google.com"
Me.WebRequest.Navigate(New Uri(url))
'Implement timer here? (me.refresh)?
End Sub
Private Sub NumericUpDown1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SelectBoat.ValueChanged
boatid = SelectBoat.Value
SelectBoat.Maximum = 10
SelectBoat.Minimum = 1
Lbboatid.Text = boatid
End Sub
Private Sub btnsequence_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsequence.Click
Dim i As Integer
boatid = i
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RefreshTimer.Tick
RefreshTimer.Enabled = True
RefreshTimer.Interval = 30000
End Sub
Private Sub main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Datetime.Text = Now.ToString
googlemaps()
End Sub
End Class

The method that has to be executed every certain period of time should be put on the
Timer1_Tick event as well. This is a small implementation try it and see if it works adapting your code accordingly:
Set up your desired Timer properties:
Click on the Timer on the Design View and on its Properties Box List set:
Interval property on 30000 (The Event will fire every 30 seconds)
Enabled on True (The Timer will start working after your form is loaded)
Then on your Codebehind
private void ShowMessage()
{
MessageBox.Show("Hello Timer");
}
private void timer1_Tick(object sender, EventArgs e)
{
ShowMessage();
}
Also here is a working implementation according to the code you posted, as for what i understand out of your code you want the browser to refresh every certain seconds as well as the numeric up and down control show the value of the variable set on boatId, this code does that:
Set the minimum and maximum properties of your numeric up down control on the Properties box of it (right click on the control in design view and search for those two properties)
Then try the following;
Public boatid As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.lblDate.Text = Now.ToString()
''Set a bigger winform to show the browser page better
Me.Width = 800
Me.Height = 600
googlemaps()
End Sub
''The browser will be refreshed every n seconds) according to what you have set on interval property of the timer control
Sub googlemaps()
Dim url As String = "http://www.google.com"
Me.WebBrowser1.Navigate(New Uri(url))
End Sub
''Loop over this method using the Tick event, while doing that verify the value
''of the boatid variable and if its less than the maximun value allowed by the numeric
''updown control increment it in one unit, then show it on the numeric selected value
''as well on the label control
Private Sub ChangeBoatIdValueCycling()
If boatid < 10 Then
boatid += 1
Else
boatid = 1
End If
Me.NumericUpDown1.Value = boatid
Me.lblBoatId.Text = boatid.ToString()
End Sub
''This wil show the id on the label text when you click up and down the numeric control
Private Sub NumericUpDown1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
Me.lblBoatId.Text = Me.NumericUpDown1.Value.ToString()
End Sub
''This will set a variable with value 5 that will get shown selected on the numeric
''control as well as visible on the label text, the value will be shown because
''it exists in the range of 1 to 10 that is your requeriment.
Private Sub btnsequence_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsequence.Click
Dim i As Integer = 5
boatid = i
Me.NumericUpDown1.Value = boatid
Me.lblBoatId.Text = boatid.ToString()
End Sub
''Needed to repeat the form refresh and boatid cycling every n seconds according to your Interval property
''value
Private Sub RefreshTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RefreshTimer.Tick
googlemaps()
ChangeBoatIdValueCycling()
End Sub
I hope it helps. Let me know how it goes.

Related

Latency picking up click event

I am having a little problem with latency when I check a checkbox on and try to drag and drop. When I select one checkbox and try to move it over it won't move. If I have click that checkbox and click on a different row then try to move it will work. It works the same no matter how many I check it won't get the newest row without clicking somewhere else first. Do I need to add another event to handle or pick up that the box now has been checked?
Private Sub datagridview_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles datagridview.MouseDown
mouseDownPosition = e.Location
End Sub
Private Sub datagridview_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles datagridview.MouseMove
If CheckMouseMovement(sender, datagridview, e) Then
listofBuilds = New List(Of Build)
For Each row As DataGridViewRow In dataGridView.Rows
If Convert.ToBoolean(row.Cells.Item(0).Value) Then
Dim t As Build = DirectCast(row.DataBoundItem, Build)
listofBuilds.Add(t)
End If
Next
If listofBuilds.Count > 0 Then
dataGridView.EndEdit()
dataGridView.DoDragDrop(sender, dropEffect)
End If
End If
End Sub
Private Sub TabControl_DragEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TabControl.DragEnter
e.Effect = DragDropEffects.All
End Sub
Private Sub TabControl_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TabControl.DragDrop
Dim DropPage As TabPage = GetTabPageByTab(TabControl.PointToClient(New Point(e.X, e.Y)))
If DropPage IsNot TabControl.SelectedTab Then
If DropPage Is Page1 Then
If DropPage Is Page2 Then
If DropPage Is Page3 Then
//etc
End If
End If
End Sub
Private Function GetTabPageByTab(ByVal point As Point) As TabPage
For i As Integer = 0 To TabControl.TabPages.Count - 1
If TabControl.GetTabRect(i).Contains(point) Then
Return TabControl.TabPages.Item(i)
End If
Next
Return Nothing
End Function
Adding a call to datagridview.EndEdit() at the beginning of the datagridview_MouseMove method will commit the current edit operation and update the source data so that you can see the updated value in your code.

Timer and updating label text

im trying to make an app to show when there is somthing "new". So i made Label1 and Timer. I want every secound to check if in status.txt text is 0 to show nothing, if its 1 to show text from text.txt. This is what try so far:
Public Class Form1
Dim client As WebClient = New WebClient()
Dim status As String = client.DownloadString("http://force-play.com/launcher/status.txt")
Dim information As String = client.DownloadString("http://force-play.com/launcher/text.txt")
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Start()
Timer1.Interval = 1000
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If status = 0 Then
Label1.Text = "No New Info"
End If
If status = 1 Then
Label1.Text = information
End If
End Sub
End Class
Try setting the status string at the beginning of your Timer1_Tick method.

Passing variable from one form to another in vb.net

I've looked this question up 10 times but each answer is too specific to the question.
I have two public classes, one per form.
The first form has a textbox and two buttons:
Public Class frmAdd
Public addvar As String
Public Sub UltraButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddNote.Click
If txtAdd.Text = String.Empty Then
MsgBox("Please complete the notes textbox!")
Else
addvar = txtAdd.Text
MsgBox(addvar)
Close()
End If
End Sub
Public Sub UltraButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
Me.Close()
End Sub
End Class
In the second form I want to take that addvar variable and say
Public Sub saveButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles addButton.Click
frmAdd.show()
me.textbox1.text = addvar
How do I get this to work in vb.net?
You need to read the field out of the frmAdd value
Me.textbox1.Text = frmAdd.addvar
Note that this value won't be available until the form has completed, and is closed (Me.close). Hence you want to use ShowDialog (doesn't return until form is closed) vs. Show (which returns immediately after displaying the form).
frmAdd.ShowDialog()
Me.textbox1.Text = frmAdd.addvar

How to print certain indexes based off of certain check boxes being checked

Below I have an array and in my design I have a check list box with 10 options. For example, if boxes 1 and 2 were checked, I would only want to print Indexes 0 and 1 ONLY. I have a button that prints all of the array members (included below) and that is what I want to make print only selected items. I have tried using a switch but that file had gotten corrupted and I am lost. Thank you. (Language is VB)
Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
btn1.Click
Dim strDecimal(9) As String
strDecimal(0) = FormatPercent(0.0146175)
strDecimal(1) = FormatPercent(0.0345324585)
strDecimal(2) = FormatPercent(0.09324543575)
strDecimal(3) = FormatPercent(0.07346475)
strDecimal(4) = FormatPercent(0.0772346615)
strDecimal(5) = FormatPercent(0.42234234654)
strDecimal(6) = FormatPercent(0.6246264664)
strDecimal(7) = FormatPercent(0.4524642234)
strDecimal(8) = FormatPercent(0.6876543534)
strDecimal(9) = FormatPercent(0.6876543534)
For num As Integer = 0 To strDecimal.Length - 1
listArrays.Items.Add(strDecimal(num))
Next
End Sub
Private Sub clearList()
listArrays.Items.Clear()
End Sub
Private Sub btn2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn2.Click
clearList()
End Sub
Assuming you're using a CheckedListBox and want to know which items are Checked:
Private Sub btn3_Click(sender As Object, e As EventArgs) Handles btn3.Click
For Each itm As String In listArrays.CheckedItems
Debug.Print(itm)
Next
End Sub

How can I update a label's text when a row in the datagridview is changed?

On my form I have a label (lblBalance) and I have a DGV which is populated from an Access database. If I add, delete or update a row, how can I refresh the label text so it reflects the new balance?
This is my frmMain code so far:
Public Class frmMain
Private Sub TransactionsBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TransactionsBindingNavigatorSaveItem.Click
Me.Validate()
Me.TransactionsBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.CheckingDataSet)
End Sub
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'CheckingDataSet.Transactions' table. You can move, or remove it, as needed.
Me.TransactionsTableAdapter.Fill(Me.CheckingDataSet.Transactions)
lblTotalCredits.Text = BalanceTotal().ToString("c")
End Sub
Private Function BalanceTotal() As Double
Dim tot As Double = 0
Dim i As Integer = 0
For i = 0 To TransactionsDataGridView.Rows.Count - 1
tot = tot + Convert.ToDouble(TransactionsDataGridView.Rows(i).Cells(3).Value)
Next i
Return tot
End Function
End Class
The BindingSource control has a ListChanged event you can try using to update your balance label.
Private Sub TransactionsBindingSource_ListChanged(_
sender As Object, _
e As ListChangedEventArgs) _
Handles TransactionsBindingSource.ListChanged
lblTotalCredits.Text = BalanceTotal().ToString("c")
End Sub