Click here to Skip to main content
15,881,757 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
VB
Private Sub cmd1_Click()
If X=False Then
	cmd1.Caption="Area 1 ON"
	ClrPortBit &H37A,1
	X= True
Else
	cmd1.Caption="Area 1 OFF"
	SetPortBit &H37A,1
	X=False
End If
End Sub

Private Sub cmd2_Click()
If Z=False Then
	cmd2.Caption="Area 2 ON"
	ClrPortBit &H37A,0
	Z= True
Else
	cmd2.Caption="Area 2 OFF"
	SetPortBit & H37A,0
	Z=False
End If
sensor= lblwater.Caption
If sensor =0 Then
	Label2.Caption="The Power is switched off from Generation site."
	If X=True Then
		MSComm1.Output="at"
		Call delay
		MSComm1.Output=Chr(13)
		Call delay
		MSComm1.Output="at+cmgf=1"
		Call delay
		MSComm1.Output=Chr(13)
		Call delay
		MSComm1.Output="at+cmgs="
		Call delay
		MSComm1.Output=Chr(34)
		Call delay
		MSComm1.Output=txtno1.Text
		Call delay
		MSComm1.Output=Chr(34)
		Call delay
		MSComm1.Output=Chr(13)
		Call delay
		MSComm1.Output=Label2.Caption & DateTime.Now 'gsm message
		Call delay
		MSComm1.Output=Chr(26)
		Call delay
		MSComm1.Output="at+cmgs="
		Call delay
		MSComm1.Output=Chr(34)
		Call delay
		MSComm1.Output=txtno2.Text
		Call delay
		MSComm1.Output=Chr(34)
		Call delay
		MSComm1.Output=Chr(13)
		Call delay
		MSComm1.Output=Label2.Caption & DateTime.Now 'gsm message
		Call delay
		MSComm1.Output=Chr(26)
		Call delay
		cmdgsm.Caption="GSM OFF"
		X=False
	End If
ElseIf sensor = 8 Then
	Label2.Caption = "The Power is switched off between Generation site and Sub Station"
	If X = True Then
		MSComm1.Output = "at"
		Call delay
		MSComm1.Output = Chr(13)
		Call delay
		MSComm1.Output= "at+cmgf=1"
		Call delay
		MSComm1.Output = Chr(13)
		Call delay
		MSComm1.Output = "at+cmgs="
		Call delay
		MSComm1.Output= Chr(34)
		Call delay
		MSComm1.Output= txtno1.Text
		Call delay
		MSComm1.Output= Chr(34)
		Call delay
		MSComm1.Output = Chr(13)
		Call delay
		MSComm1.Output = Label2.Caption & DateTime.Now 'gsm message
		Call delay
		MSComm1.Output = Chr(26)
		Call delay
		MSComm1.Output="at+cmgs"
		Call delay
		MSComm1.Output= Chr(34)
		Call delay
		MSComm1.Output= txtno2.Text
		Call delay
		MSComm1.Output= Chr(34)
		Call delay
		MSComm1.Output = Chr(13)
		Call delay
		MSComm1.Output = Label2.Caption & DateTime.Now 'gsm message
		Call delay
		MSComm1.Output = Chr(26)
		Call delay
		cmdgsm.Caption = "GSM OFF"
		X=False
	End If
ElseIf sensor = 24 Then
	Label2.Caption = "The Power is switched off between Substation and areas."
	If X = True Then
		MSComm1.Output = "at"
		Call delay
		MSComm1.Output=Chr(13)
		Call delay
		MSComm1.Output="at+cmgs=1"
		Call delay
		MSComm1.Output = Chr(13)
		Call delay
		MSComm1.Output="at+cmgs="
		Call delay
		MSComm1.Output = Chr(34)
		Call delay
		MSComm1.Output=txtno1.Text
		Call delay
		MSComm1.Output = Chr(34)
		Call delay
		MSComm1.Output = Chr(13)
		Call delay
		MSComm1.Output = Label2.Caption & DateTime.Now 'gsm message
		Call delay
		MSComm1.Output = Chr(26)
		Call delay
		MSComm1.Output = "at+cmgs="
		Call delay
		MSComm1.Output=Chr(34)
		Call delay
		MSComm1.Output = txtno2.Text
		Call delay
		MSComm1.Output = Chr(34)
		Call delay
		MSComm1.Output = Chr(13)
		Call delay
		MSComm1.Output = Lable2.Caption & DateTime.Now 'gsm message
		Call delay
		MSComm1.Output = Chr(26)
		Call delay
		cmdgsm.Caption = "GSM OFF"
		X= False
	End If
ElseIf sensor = 56 Then
	Label2.Caption = "The Power is switched off between Substation and area1"
	If X = True Then
		MSComm1.Output = "at"
		Call delay
		MSComm1.Output = Chr(13)
		Call delay
		MSComm1.Output = "at+cmgf=1"
		Call delay
		MSComm1.Output=Chr(13)
		Call delay
		MSComm1.Output = "at+cmgs="
		Call delay
		MSComm1.Output = Chr(34)
		Call delay
		MSComm1.Output = txtno1.Text
		Call delay
		MSComm1.Output = Chr(34)
		Call delay
		MSComm1.Output = Chr(13)
		Call delay
		MSComm1.Output = Label2.Caption & DateTime.Now 'gsm message
		Call delay
		MSComm1.Output = Chr(26)
		Call delay
		MSComm1.Output = "at+cmgs="
		Call delay
		MSComm1.Output = Chr(34)
		Call delay
		MSComm1.Output = txtno2.Text
		Call delay
		MSComm1.Output = Chr(34)
		Call delay
		MSComm1.Output = Chr(13)
		Call delay
		MSComm1.Output = Label2.Caption & DateTime.Now 'gsm message
		Call delay
		MSComm1.Output = Chr(26)
		Call delay
		cmdgsm.Caption = "GSM OFF"
		X= False
	End If
ElseIf sensor = 88 Then
	Label2.Caption = "The Power is switched off between Substation and area2"
	If X= True Then
		MSComm1.Output = "at"
		Call delay
		MSComm1.Output = Chr(13)
		Call delay
		MSComm1.Output = "at+cmgf=1"
		Call delay
		MSComm1.Output = Chr(13)
		Call delay
		MSComm1.Output = "at+cmgs="
		Call delay
		MSComm1.Output = Chr(34)
		Call delay
		MSComm1.Output = txtno1.Text
		Call delay
		MSComm1.Output = Chr(34)
		Call delay
		MSComm1.Output = Chr(13)
		Call delay
		MSComm1.Output = Label2.Caption & DateTime.Now 'gsm message
		Call delay
		MSComm1.Output = Chr(26)
		Call delay
		MSComm1.Output = "at+cmgs="
		Call delay
		MSComm1.Output = Chr(34)
		Call delay
		MSComm1.Output = txtno2.Text
		Call delay
		MSComm1.Output = Chr(34)
		Call delay
		MSComm1.Output = Chr(13)
		Call delay
		MSComm1.Output = Label2.Caption & DateTime.Now 'gsm message
		Call delay
		MSComm1.Output = Chr(26)
		Call delay
		cmdgsm.Caption = "GSM OFF"
		X= False
	End IF
Else
	Label2.Caption = "The power is there in the entire distribution grid"
End IF
If Y = True Then
	Label5.Caption = Time$
	Label6.Caption = Date$
	If Check1.Value = 1 Then
		device1 = True
	Else
		device1 = False
	End If
	If Check2.Value  = Then
		device2 = False
	End If
	If device1=False Then
		ClrPortBit &H37A, 1
		ElseIf (Time$ > Text1.Text And Time$<text2.text and="" device1="True)" mode="hold" />SetPortBit &H37A, 1
	Else
		ClrPortBit &H37A, 1
	End If
	If device2 = False Then
		ClrPortBit &H37A, 2
		ElseIf (Time$ > Text3.Text An Time$<text4.text and="" device2="True)" mode="hold" />SetPortBit &H37A, 0
	Else
		ClrPortBit &H37A, 0
	End If
End If


What I have tried:

I HAVE TRIED TO RUN THIS CODE IN WINDOWS FORM APPLICATION
Posted
Updated 18-Apr-16 11:48am
v4
Comments
Garth J Lancaster 16-Apr-16 22:25pm    
Not sure what you want from us - there are way too many unknowns in this snippet of code for us to magically make it work - I could attempt it, but without requirements & specs on what it's all supposed to do, it would be guesswork
Sergey Alexandrovich Kryukov 17-Apr-16 0:16am    
Considering, for example, a number of repeating identical statements, this code is written by someone who has no clue how to do programming, so it hardly deserves any attention.
—SA
Garth J Lancaster 17-Apr-16 0:30am    
no doubt there are good ways to write code, even if you HAD to use VB.Net - this isnt one of them :-(
Sergey Alexandrovich Kryukov 17-Apr-16 0:51am    
...and, from the other hand, there is no such language that you could not screw up code. :-)
—SA
Member 12465019 18-Apr-16 17:37pm    
Hello Sir, Sorry for replying late. I'm a final year engineering student in electronics engineering student. So for my final year project. I have an embedded system project. So I have used an lpt/db-25 connector with the PC for parallel communication. So the 8 data lines of the connector read the values in the PC.
So the VB code will help me display the graphic user interface just like SCADA. That Graphic user interface will display the power loss values. Sir, since vb is out of my expertise or even domain, I found this code from someone who had built the same project. I'm running out of time to make this code work. It would be grateful if you can help me run this code in any way possible

1 solution

That looks like old ass VB6 code. It also looks like it requires an external library that you may not have. I get the feeling you found this code on the web somewhere and don't have that library.

As the code stands right now, it's impossible to run it. The code is setting port values, which VB doesn't have a function for and Windows won't let you do because it abstracts all the hardware from your code.

You need an external library to do it and the code you've posted proves that.
 
Share this answer
 
v3
Comments
Garth J Lancaster 18-Apr-16 22:12pm    
it also looks like code for a serial interface, whereas in his reply to me, he's mentioned parallel :sigh: - I dont know who voted '1' for your answer, so they can bite me and Im going to try to counteract it
Dave Kreskowiak 18-Apr-16 23:38pm    
I changed my answer. My original was not so nice because of a very frustrating situation I was in at the time and I boiled over a bit.
Garth J Lancaster 19-Apr-16 0:15am    
s'ok - we all do it
Member 12465019 7-May-16 13:58pm    
@Garth J Lancaster, @Dave Kreskowiak, @Garth J Lancaster... Sir, If you'll send me your email-id I can send you the project details... Since over here I can't paste images or upload any documents, images
Dave Kreskowiak 7-May-16 14:46pm    
That's not going to happen. First, I'm not running code I don't trust on my machine and second, there is an external library that code needs that I'm not going to have nor am I going to chase it down.

I also don't have VB6 as it's been dead for quite a long time now and I've been using .NET for the last 15 years.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900