|
Why would you need a loop?
If you wanted to fill all three pictureboxes every time the button was clicked, a loop might be useful, but not for individual fills.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
I was thinking to avoid to write the same thing three times.
For example I am imaging that it could like the following:
for (i=0, i<3, i++)
PictureBoxi.Image = CropBitmap(GetWindowPicture(PictureBox2.Handle.ToInt32), 100, 100, 50, 50)
so the first time the result would be
PictureBox1.Image = CropBitmap(GetWindowPicture(PictureBox2.Handle.ToInt32), 100, 100, 50, 50)
the second
PictureBox2.Image = CropBitmap(GetWindowPicture(PictureBox2.Handle.ToInt32), 100, 100, 50, 50)
and the third time
the second
PictureBox3.Image = CropBitmap(GetWindowPicture(PictureBox2.Handle.ToInt32), 100, 100, 50, 50)
May I accomplised that in VB.NET, to create the full name of the Picturebox using a variable?
|
|
|
|
|
athinaix wrote: to create the full name of the Picturebox using a variable
I'm afraid not.
You could put the pictureboxes into a collection and get at each like:
Dim activePicBox AS PictureBox = myPBCollection(i)
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
May be like this(in C#):
((PictureBox)(this.Controls["PictureBox"+i.ToString()]).Image
Not sure if doing things like these are recommended.
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
I am looking to retrieve a value from an existing file and copy it to a new one, for the sake of a header. The value is a date. I am using a mix of old and new files, some have the information I need and it has to be copied to the new file, some older files don't and new data will need to be written in it's place to the header.
The question is, can I use ->
If ('Old Chicken' Is Nothing) Then
'Fill the freezer'
Else
'Put Old Chicken In New Freezer'
End If
Or would it be sesible/is it acceptable to ->
Try
'To put old chicken in new freezer'
Catch As Exception
'Call it quits and just fill the freezer'
End Try
Any help would be greatly appreciated.
|
|
|
|
|
The if/else approach. What if you get an exception in the try block? (Not because Old chicken is nothing but some other reason)
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
Good good. I'm pretty new to programming and VB especially. I'm just worried that the if/else would just throw an error if the object I was trying to acquire did not exist at all and wasn't just empty. Thus the code would exit anyway, the try/catch would solve this. But yes, I take your point, if there was any other error in this snippet, it would be rather sidelined.
|
|
|
|
|
Best would be to use if/else inside try/catch.
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
|
Maybe I should reword my question... All these answers are helpful (as a n00b anything that helps me learn is a good thing, so thanks).
But when I test for the is MyChicken = 'null' (or similar), I get a NullReferenceException. I'm guessing because the old files header does not include a reference to the 'Chicken' I seek, so it looks for the chicken doesn't find it and exits code, saying it's not there, not even bothering to check for it's 'nullness'.
I guess I mean...
If MyChicken is there at all
'Put it in the freezer'
Else
'Create a chicken and put in in the new freezer'
End If
If you'll excuse all the poultry references.
|
|
|
|
|
You're on the right track though.
The best way to go is to start of with the Try Catch block and MsgBox(ex.ToString) in the Catch clause. Turning on line numbers in your code editor is also a good idea.
Then when you get these NullReferenceExceptions, you'll know exactly which object is causing the error.
Next thing is combining checks, on separate lines, so that you always first check for Is Nothing, and only then for anything else like null or empty strings, etc.
My advice is free, and you may get what you paid for.
|
|
|
|
|
Thanks for the proTip. I'm testing the object key for 'is nothing', I figured it would be the best place to start, this is where I get the error, on the first line of said conditional (if null etc...).
I have since discovered .contains, useful. Having jumped from C++/C all these VB short cuts and lack of pointers is giving me much fun/joy/sarcasm. Thanks for all your help though guys, there are some good snippets there.
|
|
|
|
|
Depending upon how you are pulling the value before comparing it, you may be able to check for nulls with the following statement:
If myValue Is DBNull.Value Then
'Handle the Null value
Else
'Value was not null
End If
Hope this helps.
|
|
|
|
|
I try to translate code from c++ to vb6,
in C++ i have:
unsigned char a = 3
unsigned char b = 188
unsigned char c
c = a^b
I get an answer c = 191.
I try the same in VB6
dim a as byte
dim b as byte
dim c as byte
a = 3
b = 188
c = a^B
I get Overflow
How do i get the same result ?
i tryed using combinations with MOD 256 but no success.
thanks.
|
|
|
|
|
Well, your basic problem is that you're using VB6, which was always crap, and has been unsupported for a long time. Why are you still using it ?
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Well, it is an additional feature im adding to a program allready written in VB6.
the question is what would be easier, coverting the whole program to smth else
or just trying to fix my problem.
|
|
|
|
|
It depends. If the program is going to live for a long time, I'd consider converting it to a real language.
If all else fails, you can do what VB6 users always did, get a C++ dll to do the real work. I don't know why the operation you're trying is failing, I suspect the answer is that the ^ does something different in VB6 to c++.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
IIRC it does.
^ in C/C++ is Bitwise Exclusive Or
^ in VB6 is exponentiation (raise to power)
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
|
|
|
|
|
"^" in C++ is bitwise XOR while in VB, it is power(exponent). Maybe that is the reason you are getting error.
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
Yep, I eventually figured it out,
im not so familiar with c++...
thanks.
|
|
|
|
|
using VB6 is a real bad idea. Use some newer Versions as Vb.net.
Always remember VB6 code isnt portable to VB.net, so VB6 is lost.
Press F1 for help or google it.
Greetings from Germany
|
|
|
|
|
Hi
I need to shutdown remote systems running on windows xp with Dotnet Framework 1.1 installed. The user is limited on these machines.
I have used the following methods to shutdown the systems.
1. wmi
Dim oOS, oOperatingSystem As Object
oOS = GetObject("winmgmts:{(Shutdown)}").ExecQuery("Select * from Win32_OperatingSystem")
For Each oOperatingSystem In oOS
oOperatingSystem.Win32Shutdown(nForcePowerDown)
Next
2. shutdown.exe of xp
The problem is using the wmi sometime fails for reasons I don't know. The other method needs Admin privileges. Which is also an overhead.
What should I do? Use the API or there is some other way?
Please help as search over internet has not helped me much.
Thanks
reman
|
|
|
|
|
Let's just assume that your reasons for wanting to do this are entirely legitimate.
Think about it, if it were possible to just shut down a remote system, without admin privileges, what would keep hackers from doing so?
My advice is free, and you may get what you paid for.
|
|
|
|
|
If you want to do remote shutdown, you need Admin privileges on the remote machine to do it. There is no way around it, for obvious reasons.
|
|
|
|
|
Imports System.Net
Imports System.Net.NetworkInformation
Imports System.Text
Protected Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button4.Click
Public Shared Sub ShowTcpStatistics(ByVal version As NetworkInterfaceComponent)
Dim properties As IPGlobalProperties = IPGlobalProperties.GetIPGlobalProperties()
Dim tcpstat As TcpStatistics = Nothing
txtbox.Text("")
Select Case version
Case (NetworkInterfaceComponent.IPv4)
tcpstat = properties.GetTcpIPv4Statistics()
txtbox.Text("TCP/IPv4 Statistics:")
Exit Select
Case (NetworkInterfaceComponent.IPv6)
tcpstat = properties.GetTcpIPv6Statistics()
txtbox.Text("TCP/IPv6 Statistics:")
Exit Select
Case Else
Throw (New ArgumentException("version"))
' break;
End Select
txtbox.Text(" Minimum Transmission Timeout............. : {0}", tcpstat.MinimumTransmissionTimeout)
txtbox.Text(" Maximum Transmission Timeout............. : {0}", tcpstat.MaximumTransmissionTimeout)
txtbox.Text(" Connection Data:")
txtbox.Text(" Current ............................ : {0}", tcpstat.CurrentConnections)
txtbox.Text(" Cumulative .......................... : {0}", tcpstat.CumulativeConnections)
txtbox.Text(" Initiated ........................... : {0}", tcpstat.ConnectionsInitiated)
txtbox.Text(" Accepted ............................ : {0}", tcpstat.ConnectionsAccepted)
txtbox.Text(" Failed Attempts ..................... : {0}", tcpstat.FailedConnectionAttempts)
txtbox.Text(" Reset ............................... : {0}", tcpstat.ResetConnections)
txtbox.Text("")
txtbox.Text(" Segment Data:")
txtbox.Text(" Received ........................... : {0}", tcpstat.SegmentsReceived)
txtbox.Text(" Sent ................................ : {0}", tcpstat.SegmentsSent)
txtbox.Text(" Retransmitted ....................... : {0}", tcpstat.SegmentsResent)
txtbox.Text("")
End Sub
|
|
|
|