Shoutbox

Visual Basic 2008 - Reloading/Refreshing Same form - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: Visual Basic 2008 - Reloading/Refreshing Same form (/showthread.php?tid=87746)

Visual Basic 2008 - Reloading/Refreshing Same form by Quantum on 12-14-2008 at 06:31 PM

Ok so i have 1 form called Form1.

There is a button on there called b2 and when that's clicked i need it to reload the whole form (form1). I can't figure out a way of doing this. If i do Form1.Exit() then load it or show i can't as it's gone and theres nothing to do it :P

So how can i reload the form?


RE: Visual Basic 2008 - Reloading/Refreshing Same form by Stigmata on 12-14-2008 at 07:33 PM

reload? like start afresh?
Form1.Refresh() not what you want?

or hide it and show it?
Form1.Hide()
Form1.Show()


edit: but in vb2008 you should use me if you are calling it from that form :)

so

Me.Refresh()
Me.Hide()
etc


RE: Visual Basic 2008 - Reloading/Refreshing Same form by Quantum on 12-14-2008 at 08:27 PM

Ok, i did me.refresh but it's no reloading all the things in the form.

When the form stats it pings 5 servers and displays if there online or offline. I need it to reload it so it pings them i again. This can be done by refreshing the form right?

When i do me.refresh() it does not reload the results :S


RE: Visual Basic 2008 - Reloading/Refreshing Same form by vaccination on 12-14-2008 at 08:44 PM

I believe this will be due to Refresh() only refreshing the graphical elements of the form. If you want to rerun code you'll want to make the button perform a Call function.

However this won't empty the listbox(i presume that's what you're using) and will just append the results to it, you'll need to clear it first.


RE: Visual Basic 2008 - Reloading/Refreshing Same form by Quantum on 12-14-2008 at 08:50 PM

Can you give me an example?


RE: Visual Basic 2008 - Reloading/Refreshing Same form by Stigmata on 12-14-2008 at 08:54 PM

put the ping'ing stuff, loading list box etc in a procedure.

call the procedure on form load, call it again after the button press?


RE: Visual Basic 2008 - Reloading/Refreshing Same form by vaccination on 12-14-2008 at 09:06 PM

Yeah, basically.

code:
Public Class form1

   Private sub Ping()
  -code-
   End Sub

   Private sub Button_Click() Handles Button.Click
   Call Ping()
   End Sub


That's very basic, but something like that.
RE: Visual Basic 2008 - Reloading/Refreshing Same form by Quantum on 12-14-2008 at 09:59 PM

Ok well the code for that form starts like

code:
Private Sub main1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Then my

code:
If My.Computer.Network.Ping("xx.xxx.xx.xx") Then
            PictureBox1.Show()
        Else
            PictureBox10.Show()
        End If

(there more than one)

It ends with the usual

code:
End Sub

How do i add it in? I can't seem to do it without errors :P :S



RE: Visual Basic 2008 - Reloading/Refreshing Same form by Stigmata on 12-14-2008 at 10:01 PM

are you learning vb atm?


Look up procedures :)

It's prob better its something you lookup and learn yourself because you'll find it useful in future :)


RE: Visual Basic 2008 - Reloading/Refreshing Same form by Quantum on 12-14-2008 at 10:17 PM

Ok, i've got it partly working.

When the form loads this command is given:

code:
Call Ping()


And when the button is pressed that does the same command.

The code inside Ping() pings a server and makes a image visible if it gets a response or else makes an image next to it visible if there no response.

But if all servers are online there will be a list of images visable. Fair enough untill i refresh that list by pressing the button with

Call Ping()

in it and if a server is offline it will make the offline and online image active.

Do you get me.

So when the form loads there is

1 IMAGE
2 IMAGE
3 IMAGE
4 IMAGE
5 IMAGE

And if i refresh and one goes offline its like

1 IMAGE
2 IMAGE IMAGE
3 IMAGE
4 IMAGE
5 IMAGE

When i need it to be

1 IMAGE
2              IMAGE
3 IMAGE
4 IMAGE
5 IMAGE




RE: Visual Basic 2008 - Reloading/Refreshing Same form by Stigmata on 12-14-2008 at 10:20 PM

then hide the images you don't want to show?

code:
If My.Computer.Network.Ping("xx.xxx.xx.xx") Then
            PictureBox1.Show()
            PictureBox10.Hide()

        Else
            PictureBox10.Show()
            PictureBox1.Hide()
End If


RE: Visual Basic 2008 - Reloading/Refreshing Same form by Quantum on 12-14-2008 at 10:21 PM

What like

If My.Computer.Network.Ping("xx.xxx.xx.xx") Then
            PictureBox1.Show()

        Else
            PictureBox10.Show()
            PictureBox1.Hide()
End If


RE: Visual Basic 2008 - Reloading/Refreshing Same form by Stigmata on 12-14-2008 at 10:26 PM

nope, like what I showed you :)


RE: Visual Basic 2008 - Reloading/Refreshing Same form by Quantum on 12-14-2008 at 10:30 PM

I did that but if one is online then offline then online, 2 images are shown.. :S


RE: Visual Basic 2008 - Reloading/Refreshing Same form by vaccination on 12-15-2008 at 10:06 AM

Just completely clear all the images inside your ping Sub. That way when you call it they'll all be generated right.

[so, in your Sub Ping() your first bit of code will be PictureBox1.Hide(), PictureBox2.Hide() etc, then you have your ping stuff + showing the pictures]


RE: Visual Basic 2008 - Reloading/Refreshing Same form by Quantum on 12-15-2008 at 05:56 PM

Thanks :D

Got it working :P

If i ping a server sometimes  the ping messes up and it detects the server as offline. It's not though. Is there a better way to see if a server is offline or online?


RE: Visual Basic 2008 - Reloading/Refreshing Same form by Ezra on 12-15-2008 at 07:14 PM

quote:
Originally posted by Quantum
If i ping a server sometimes  the ping messes up and it detects the server as offline. It's not though. Is there a better way to see if a server is offline or online?

check if the service that it is providing is working, so a http server, try to download the index page, or just a HEAD request (will save bandwidth), ftp try to connect, etc...
RE: Visual Basic 2008 - Reloading/Refreshing Same form by pillowmurder on 01-10-2009 at 03:43 AM

very simple to reload a form.

use another form, in it have this code execute either by load or another objects method.

form1.close() 'form you want reloaded closes
form1.visible = true  'form you want reloaded opens
form2.close() 'form that did the reload closes



yours,
PM


RE: RE: Visual Basic 2008 - Reloading/Refreshing Same form by andrewdodd13 on 01-10-2009 at 11:48 AM

quote:
Originally posted by pillowmurder
very simple to reload a form.

use another form, in it have this code execute either by load or another objects method.

form1.close() 'form you want reloaded closes
form1.visible = true  'form you want reloaded opens
form2.close() 'form that did the reload closes



yours,
PM
This shouldn't work in VB 2008, because forms are now stored as classes rather than objects, so form1 is the class.

What you would be better off doing, is making a module, and using Sub Main and having a global in the module called form1Instance, code like this:

Visual Basic code:
Dim form1Instance As Form1
 
Sub Main
  form1Instance = new Form1
  form1Instance.Show()
End Sub
 
Sub Reset
  form1Instance.close()
  form1Instance.show()
End Sub

To Reset the form, call Module1.Reset. At least... it should work. :P
RE: Visual Basic 2008 - Reloading/Refreshing Same form by BV on 02-08-2013 at 08:59 AM

Hi in case your still interested in finding the solution for this.

This is what worked for me.

I needed to refresh the data that the form has, but the microsoft refresh button is not doing the trick, so here is what i did:

I created a sub procedure called "loadReport", which must happen at form load, and on click event of refresh button.

Here is how my code looks like:

Private Sub loadReport()
        Try
            'TODO: This line of code loads data into the 'myDataSet.Events' table. You can move, or remove it, as needed.
            Me.EventsTableAdapter.Fill(Me.myDataSet.Events)
            'TODO: This line of code loads data into the 'myDataSet.eventtable' table. You can move, or remove it, as needed.
            Me.eventtableTableAdapter.Fill(Me.myDataSet.eventtable)
            ' Me.EventsTableAdapter.Fill(Me.myDataSet.Events)
            Me.ReportViewer1.RefreshReport()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'       Call the sub procedure on form load
        loadReport()
    End Sub

Private Sub btnRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRefresh.Click
        'Call the sub procedure on refresh button
        loadReport()
    End Sub;)