|
Where does frmMain come from ? What do you mean by 'not working' ? What happens ? Did you want help ? You seem to be setting a puzzle rather than giving us the info we need to try to help here.
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.
|
|
|
|
|
Hi,
I wanted to create an app to incorprate on my program where the user has to type in a serial number before the applicaion is then displayed. Then when the application is then re-run the serial number form is NOT shown due to the serial number having already been inputted.
I will be honest i am not the greatest programmer so bear with me.
Here is the code i have currently used howver this HALF works.
This will allow the user to enter the serial code and show form 2 however when the user re-runs the app then it doesn't run?!?! The form flashes up for .1 of a second and then disappears.
Public Class Form1
Dim FILE_NAME As String = ("serial.txt")
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim objReader As New System.IO.StreamReader(FILE_NAME)
Do Until objReader.EndOfStream
If txtserial.Text = objReader.ReadLine Then
Startnot.Checked = False
Form2.Show()
Me.Hide()
Else
Try
If txtserial.Text = objReader.ReadLine.Trim Then
End If
Catch Ex As Exception
End Try
Label1.Text = "Invalid CDKey"
End If
Loop
objReader.Close()
End Sub
Private Sub Form1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Leave
If Me.Visible = False Then
Form2.Show()
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
SetAttr(FILE_NAME, FileAttribute.Normal)
Dim Dontshow As Boolean
Dontshow = GetSetting(My.Application.Info.ProductName, "Options", "Dont Show Me", 1)
If Dontshow = 0 Then
Form2.Show()
Call cookies()
Exit Sub
End If
Startnot.Checked = True
End Sub
Private Sub Startnot_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Startnot.CheckedChanged
SaveSetting(My.Application.Info.ProductName, "Options", "Dont Show Me", Startnot.CheckState)
End Sub
Private Sub cookies()
Me.Close()
My.Forms.Form2.Show()
End Sub
End Class
I got some previous feedback from another programmer saying
I'd start by scrapping what you have and replacing it with a seperate class. You main form should call this class, call it "Licensing", to ask if it is OK to run the app. The Licensing class has to do a few things to answer this question.
First, it has to check to see if the app has already been through the CDKey entry process and that a valid Key was entered. This could be a value written to the registry or to your AppSettings file.
If the value doesn't exist or it indicates that the license is not valid, this class would put up a new form, or even just an InputBox, asking for the CD key. Once the key is entered, it is compared against the first line of the serial.txt file. If they match, then you create/update the value tracking this in the Registry or your AppSettings file. If not, then Licensing doesn't change anything and returns False to say that it is not OK to run the app.
If the value is OK, then the method in your Licensing class would just return True to say that it is OK to run the app. There's no need to put up the CD Key entry form again.
You can get the first line of the file using:
Dim keyInFile As String ... Using sr As New StreamReader(Path.Combine(Application.StartupPath), "serial.txt")) keyInFile = fs.ReadLine() End Using
howeve i am ereally struggaling to incorprate this code so if any body could help me fix this then that would be very nice.
Many thanks
Dan
|
|
|
|
|
This looks like a disaster. Have you tried setting breakpoints in your code to see what happens that second time ? Can you give us some more specific diagnostics ?
Obviously, this is all just for fun and learning, so I won't comment again on how utterly useless your 'protection' is.
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.
|
|
|
|
|
Christian Graus wrote: Have you tried setting breakpoints
breakpoints, the points where you see your code break as you stare at the screen?
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? 59.24% waren verstandig genoeg om NEEN te stemmen; bye bye viaduct.
|
|
|
|
|
Seems that way.
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.
|
|
|
|
|
Only if you manage to compile it
|
|
|
|
|
thanks guys for all the replies. Ummm break points? I just copied and pasted the ALL the code that i used
|
|
|
|
|
Hi,
I have written a macro that sends email from MS Excel through MS Outlook. The action is triggered by a button-click. Now, the same macro does not work when I'm using Outlook Web-access. Does anybody know how I can send email from MS Excel through outlook web-access? I need help badly.
Thanks in advance .
|
|
|
|
|
With extreme difficulty. AFAIK, there is no component to interact with OWA.
|
|
|
|
|
I use DataGridView with column type CheckBox. How to verify whether CheckBoxs in this column is checked
|
|
|
|
|
Get the CheckBox cell and inspect its checked property. A bit more explanation of your problem would help.
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
How to inspect. Give me some example
|
|
|
|
|
ivo75 wrote: How to inspect
The checked property is a boolean. Put that in a if/else block and see if it is true or false. Not a VB guy hence cannot provide the code. Even if I was, I wouldn't have since I do not believe in spoon feeding at professional level (Hope you are a professional and not a student).
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
test whether the checked property is true to do whatever you want
|
|
|
|
|
Hello,
I am programming in vb.net 2005
I have two classes: Point and Line
My application is drawing ~30 to 50 lines on a picturebox.
I don't know if it is possible but I am trying to add an eventhandler to allow user to click on specific line and then to change the color of selected line.
I can't success to give to this line object a click event ability.
Is it possible?
How to do it?
Here is my snippet code:
Option Explicit On
'********START POINT*******************
Public Class MainForm
Private Line1 As Line
Private Sub MainForm_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Dim P1 As New Point(10, 30), P2 As New Point(120, 210)
Line1 = New Line(P1, P2)
Line1.DrawLine(e)
AddHandler Line1.LineClick, AddressOf LineClicked
End Sub
Private Sub LineClicked(ByVal sender As Object, ByVal e As EventArgs)
'Do something
End Sub
End Class
'********DELEGATE*******************
Public Delegate Sub LineEventHandler(ByVal sender As Object, ByVal e As EventArgs)
'********LINE CLASS*******************
Public Class Line
Inherits EventArgs
Private P1 As Point, P2 As Point
Sub New(ByVal P1 As Point, ByVal P2 As Point)
Me.P1 = P1
Me.P2 = P2
End Sub
Sub New(ByVal x1 As Single, ByVal y1 As Single, ByVal x2 As Single, ByVal y2 As Single)
Me.P1 = New Point(x1, y1)
Me.P2 = New Point(x2, y2)
End Sub
Public Sub DrawLine(ByVal e As PaintEventArgs)
Dim p As New Pen(Color.Black, 1)
Dim g As Graphics = e.Graphics
g.DrawLine(p, P1.x, P1.y, P2.x, P2.y)
End Sub
Public Event LineClick As LineEventHandler
Protected Overridable Sub OnLineClick(ByVal e As EventArgs)
RaiseEvent LineClick(Me, e)
End Sub
End Class
'********POINTC CLASS*******************
Public Class Point
Public x As Single, y As Single
Sub New(ByVal x As Single, ByVal y As Single)
Me.x = x
Me.y = y
End Sub
Property xCoord() As Single
Get
Return x
End Get
Set(ByVal value As Single)
x = value
End Set
End Property
Property yCoord() As Single
Get
Return y
End Get
Set(ByVal value As Single)
y = value
End Set
End Property
End Class
Shay Noy
|
|
|
|
|
Well, there are a few problems here. Your class line does not need to inherit from EventArgs. Instead it should inherit from Control/Usercontrol class since controls raise event. Next, the EventArgs can be replaced by LineClickEventArgs and that class should inherit from EventArgs class. This class should have properties that the parameter should provide. Then, you need to have a virtual overridable method say OnLineClick which should take in LineClickEventArgs as the parameter.
The only thing that remains now is that from where will you call OnLineClick. For this, you will need to identify if the click was on the line. You can have some property that will be set when you click the line. And in the set block, you can call the OnLineClick method.
AFAIK you can get to know if the line was clicked only in the MouseDown/MouseUp of your form. And there you can change the property of the Line class which will raise the event.
Other way of changing the line color can be this:
1. In the MouseDown/MouseUp event of the form, see if click was on line.
2. Have a flag say IsLineClicked in your form.
3. Add a bool parameter in your DrawLine and in the method have an if else that will set the color in which line will be drawn.
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
|
Welcome.
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
I have written a program in VB 2008 Express to call up my ADSL Router, login, access and save some traffic statistics. The partial code shown below has been gleaned from the interent/forums as a means to automatically login to the router. Unfortunately, this routine does not work. When the webbrowser1.navigate command is issued the router responds with another form requiring the login user name and password (these are required in unencrptyed text). The document.completed event is never reached as control is taken away from my program and held by the Internet Explore pop up page. I have tried a number of ideas but cannot overcome this proble. Is there an experienced coder who can offer some valuable advise please ?
code:
Imports System
Imports System.Net
Public Class Form1
Dim username, pswd As String
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' Part 1: Use WebBrowser control to load web page
WebBrowser1.Navigate("http://192.168.1.1/")
End Sub
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
username = "admin" : pswd = "admin"
' Part 2: Automatically input username and password
Dim theElementCollection As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("input")
For Each curElement As HtmlElement In theElementCollection
Dim controlName As String = curElement.GetAttribute("name").ToString
If controlName = "username" Then
' curElement.GetAttribute("Value")
curElement.SetAttribute("Value", username)
ElseIf controlName = "password" Then
curElement.SetAttribute("Value", pswd)
End If
Next
' Part 3: Automatically click the Login button
Dim theWElementCollection As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("input")
For Each curElement As HtmlElement In theWElementCollection
If curElement.GetAttribute("value").Equals("Login") Then
curElement.InvokeMember("click")
' javascript has a click method for we need to invoke on the current submit button element.
End If
Next
End Sub
End Class
|
|
|
|
|
In this case, the NetworkCredentials class won't do you any good. You'll have to navigate to the Login Form as normal, then in the browsers Document class, find the two textboxs for username and password, set their appropriate values, then "click" the submit button.
No, I don't have example code. I never do interaction with Web Pages.
|
|
|
|
|
Thanks for your answer Dave. It looks as though I will abandon this project in Visual Basic and move over to Pearl as this can be achieved with that language.
|
|
|
|
|
The original message was a clr20r3 message - clr20r3, P1 getmetsatdata.exe, P2 2.1.21.5, P3 4ad621e6, P4 getmetsatdata, P5 2.1.21.5, P6 4ad621e6, P7 20, P8 c6, P9 system.invalidoperationexception, P10 NIL.
I have searched the Internet, and here, and got lots of answers as to how to find out what this error is and have managed to get the program to create a text file on hitting the unhandled exception which tells me this is a 'network path not found error', so I got it to output the stack trace which tells me this:
17/10/2009 11:34:12
Unhandled exception on start up
at GetMetSatData.My.MyProject.MyForms.Create__Instance__[T](T Instance)
at GetMetSatData.My.MyProject.MyForms.get_FGetMetSat()
at GetMetSatData.My.MyApplication.OnCreateMainForm()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
This does not happen of the development machine by the way , but on 2 (or more) XP machines on which it has been installed.
My problem is that I have absolutely no idea what 'network path' this is referring to!
|
|
|
|
|
Not enough information to answer the question.
What do the app do?? What does the app do on startup?? Are you using any threading in the app?? What is going on in the threaded sections??
|
|
|
|
|
The app collects satellite pictures from the EUMETSAT site. On startup it checks the registry, but it never gets as far as that as it crashes even before it writes the first event log entry. There is no threading.
Private Sub FGetMetSat_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim intLoop As Integer = 0
Dim listErrors As New List(Of String)
Try
EventLog1.WriteEntry("MetSatGetter " & Application.ProductVersion & " was started: " & Now.ToString, EventLogEntryType.Information, 60000)
If RegistrySet() = False Then
Dim myKey As RegistryKey = My.Computer.Registry.CurrentUser.OpenSubKey("Software\DA Software\MetSat\Imagery\MSG\IR039\COL\AMERICA", False)
If myKey Is Nothing = True Then
'We may have a problem here - false overwrite
listErrors = Registry_Setup()
If listErrors.Count > 0 Then
SaveErrorList(listErrors)
End If
Else
If MsgBox("Problem: Your settings are indicating that the program registry was not installed, but one of the keys was found possibly indicating " _
& "that registry entries have been removed, or some other problem has occurred." & vbCrLf & vbCrLf _
& "MetSatGetter will now re-create the keys unless you click 'Cancel'. Note recreating the keys will overwrite any settings.", _
MsgBoxStyle.OkCancel + MsgBoxStyle.Critical, "Met Sat Getter") = MsgBoxResult.Cancel Then
'User is cancelling
m_bRegLoadError = True
For intLoop = 0 To Me.cmsMain.Items.Count - 2
Me.cmsMain.Items(intLoop).Enabled = False
Next
MsgBox("Please wait for the program to terminate. This should happen in about 1 minute, or you can terminate it yourself.", MsgBoxStyle.Information, "Met Sat Getter")
Else
listErrors = Registry_Setup()
If listErrors.Count > 0 Then
m_bRegLoadError = True
SaveErrorList(listErrors)
Else
ParseTasks()
Me.trayIcon.Text = "Met Sat Getter - " & Tasks.Count.ToString & " tasks active"
End If
End If
End If
Else
ParseTasks()
Me.trayIcon.Text = "Met Sat Getter - " & Tasks.Count.ToString & " tasks active"
End If
TempDump = SettingsKey.GetValue("TempFolder", "")
DefaultDump = SettingsKey.GetValue("DefaultFolder", "")
Me.tmrMain.Enabled = True
Me.WindowState = FormWindowState.Minimized
Catch ex As Exception
EventLog1.WriteEntry("MetSatGetter error: " & ex.Message, EventLogEntryType.FailureAudit, 60112)
EventLog1.WriteEntry("MetSatGetter failed on the load routine: " & Now.ToString, EventLogEntryType.Information, 60112)
End Try
End Sub
|
|
|
|
|
OK, all of this looks decent. I'd move on to the Form's constructor (New method) and whatever is in the InitializeComponent method. This could mean that you have a problem with a control on the form.
|
|
|
|
|