|
In VB6 i used to start my project from a Sub Main() which resided in a module.
This codei n sub main then initialised many things and called various forms, ie splash screen and so on.
However i cannot get the VB.NET windows application to start in this way. The property settings require that the start up be a form, unless i use a different app type (ie console app or other).
I'm new to VB.NET so would appreciate any best practice advise on this matter and how other developers are currently handling this.
Many Thanks
|
|
|
|
|
Every Class has a constructor and If you don't create one .NET will create one for you. As form is also a Class so it has its own Constructor it calls whenever we create an object of it so the best place to initialize things is the Constructor and in VB.NET its name is 'New' you can find the Constructor of your form inside 'Windows Form Generated Code'.
For Example:
Sub New
'Initialize Code here
End Sub
Hope it helps !
AliAmjad(MCP)
First make it Run THEN make it Run Fast!
|
|
|
|
|
I'm having difficulty finding the windows generated code. I can see the code from the forms designer but that does not contain the constructor.
|
|
|
|
|
When you click on the '+' sign besides "Windows Form Designer generated code" means when you expand it you'll see the code e.g.
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
'Your code goes here....
End Sub
I think you should buy a book because It'll really help you to clear your concepts !
hope it helps !
AliAmjad(MCP)
First make it Run THEN make it Run Fast!
|
|
|
|
|
AliAmjad
Thanks, i do have a book and have seen the code you mention before. But for some reason it is not in my current form.
When i select 'show all files' im the solution explorer, a plus sign appears next to my form which, if expanded, show me a Form.Designer.vb file and a Form.resx file.
I can see some code with 'Mybase.Disposing' in the Form.Designer.vb file but cannot find the form constructor anywhere.
I can create a constructor, with the same code as your comment and the IDE doesn't complain, but i would like to know why it is'nt there in the first place.
I have also tried adding in another form, just in case the code was accidentily deleted but this was the same.
|
|
|
|
|
first create a Start up module I alway call it mMain and than create the Main() sub.
than from the project menu select properties then from the application tab select the
startup object as sub Main()
in sub Main you should put the following code at the end:
Application.EnableVisualStyles()
Application.DoEvents()
Application.Run(MainFrm)
|
|
|
|
|
When i uncheck the 'Enable application framework' though what implication does this have?
|
|
|
|
|
Hi everybody,
I'm having some problems to code something. I want to execute a function stored in a "string". I think that is easiest to understand with an example:
Public Function GetCurrentValue() As Integer<br />
Return 67688<br />
End Function<br />
<br />
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
Dim methodName As String = "GetCurrentValue"<br />
Dim result As Integer<br />
result = ExecuteFunction(methodName)<br />
End Sub<br />
The result value should have 67688. Anybody knows how can code the "ExecuteFunction" function?
Thank you everybody
Regards,
JosBerb
|
|
|
|
|
You in need of using Delegates as they are safe type function pointers here's how to use it:
Delegate Function DelFunc() As Integer
Private Sub Form2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim InvDelfunc As New DelFunc(AddressOf MyFunction)
Dim result As Integer = InvDelfunc.Invoke()
MsgBox(result)
End Sub
Function MyFunction() As Integer
Return 8786
End Function
Hope it helps !
AliAmjad(MCP)
First make it Run THEN make it Run Fast!
|
|
|
|
|
Thank you for your answer but the problem with delegates is that only know the name of the function in execution time.
The reflection mode works properly.
Regards,
JosBerb
|
|
|
|
|
|
nlarson11 wrote: research reflection
Thank you a lot for your answer.
The reflection was a perfect solution for my problem.
Regards,
JosBerb
|
|
|
|
|
Hello,
I have a requirement where I need to use Encryption/Decryption in ASP and ASP.NET application visa versa.
I have used a Blowfish .NET dll and tried to use it but on Windows 2003 SERVER backward compatibility fails.
Please help to get a VB code through which I can encrypt and decrypt a string using a Key.
Regards,
Pavas
-----------------------
[http://longjump.com/]
Dynamic business applications that manage and coordinate teams and information
-----------------------
|
|
|
|
|
You should look at System.Security.Cryptography Namespace which contains a bunch of classes use one which suits your need.
AliAmjad(MCP)
First make it Run THEN make it Run Fast!
|
|
|
|
|
This is very simple but it works!
Public Class CL_EnCrypt
Private sPsw As String = "XAN4519CEAN4719"
Private sBox(255) As String
Private sKey(255) As String
Public Property Password() As String
Get
Return sPsw
End Get
Set(ByVal sVal As String)
sPsw = sVal
End Set
End Property
Public Function DeCrypt(ByVal sWord As String) As String
If sPsw = "" Then
MsgBox("Error you must set a password first.", MsgBoxStyle.Information, "Password not set")
Return ""
End If
Return EnDeCrypt(sWord)
End Function
Public Function EnCrypt(ByVal sWord As String) As String
If sPsw = "" Then
MsgBox("Error you must set a password first.", MsgBoxStyle.Information, "Password not set")
Return ""
End If
Return EnDeCrypt(sWord)
End Function
Private Sub RC4Initialize()
Dim sSwap As String = ""
Dim A, B As Integer
Try
For A = 0 To 255
sKey(A) = Asc(Mid$(sPsw, (A Mod sPsw.Length) + 1, 1))
sBox(A) = A
Next
B = 0
For A = 0 To 255
B = (B + sBox(A) + sKey(A)) Mod 256
sSwap = sBox(A)
sBox(A) = sBox(B)
sBox(B) = sSwap
Next
Catch ex As Exception
MessageBox.Show("Encription Error - " + ex.Message, "Encription Error", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Try
End Sub
Private Function EnDeCrypt(ByVal sPlainTxt As String) As String
'This routine does all the work. Call it both to ENcrypt and to DEcrypt your data.
Dim A, I, J, K As Integer
Dim sCipherBy, sCipher, sTemp As String
Try
sCipherBy = ""
sCipher = ""
sTemp = ""
I = 0
J = 0
RC4Initialize()
For A = 1 To sPlainTxt.Length
I = (I + 1) Mod 256
J = (J + sBox(I)) Mod 256
sTemp = sBox(I)
sBox(I) = sBox(J)
sBox(J) = sTemp
K = sBox((sBox(I) + sBox(J)) Mod 256)
sCipherBy = Asc(Mid$(sPlainTxt, A, 1)) Xor K
sCipher = sCipher + Chr(sCipherBy)
Next
Return sCipher
Catch ex As Exception
MessageBox.Show("Encription Error - " + ex.Message, "Encription Error", MessageBoxButtons.OK, MessageBoxIcon.Information)
Return ""
End Try
End Function
End Class
|
|
|
|
|
Thanks for the reply,
But I need to use the code in VB and .NET so it should work on both ASP and ASP.NET.
Hence I am looking for a code that is in VB and it has forward compatability.
Backward compatability gives issue in Windows 2003 server. So i want some tuhing with forward compatability
Regards,
Pavas
-----------------------
[http://longjump.com/]
Dynamic business applications that manage and coordinate teams and information
-----------------------
|
|
|
|
|
Below is an encryption/decryption class I have written and use.
To Encrypt, pass the the encrypt method the text to encrypt and an encryption key. As a result a string is returned with the encrypted text.
To decrypt pass the encrypted text to the decrypt method along with the original encrytion key and as a result you should now have the original text returned by the method.
Public Class Cryptography<br />
<br />
Public Shared Function Encrypt(ByVal Text As String, ByVal Key As String) As String<br />
Dim sEncrypted As String = ""<br />
Dim iKey As Integer = 0<br />
If Key.Trim.Length = 0 Then Throw New Exception("An encryption key is required")<br />
<br />
For iChar As Integer = 0 To Text.Trim.Length - 1<br />
Dim iTextChar As Integer = Asc(Text.Substring(iChar, 1))<br />
Dim iKeyChar As Integer = Asc(Key.Substring(iKey, 1))<br />
Dim iCharacterIndex As Integer = iTextChar + iKeyChar + iChar<br />
<br />
While iCharacterIndex > 255<br />
iCharacterIndex = iCharacterIndex - 255<br />
End While<br />
<br />
sEncrypted &= Chr(iCharacterIndex)<br />
iKey += 1<br />
If iKey > (Key.Trim.Length - 1) Then iKey = 0<br />
Next<br />
Return sEncrypted<br />
<br />
End Function<br />
<br />
Public Shared Function Decrypt(ByVal EncryptedText As String, ByVal Key As String) As String<br />
Dim sDecrypted As String = ""<br />
Dim iKey As Integer = 0<br />
If Key.Trim.Length = 0 Then Throw New Exception("An encryption key is required")<br />
<br />
For iChar As Integer = 0 To EncryptedText.Trim.Length - 1<br />
Dim iTextChar As Integer = Asc(EncryptedText.Substring(iChar, 1))<br />
Dim iKeyChar As Integer = Asc(Key.Substring(iKey, 1))<br />
Dim iCharacterIndex As Integer = iTextChar - iKeyChar - iChar<br />
<br />
While iCharacterIndex < 1<br />
iCharacterIndex = iCharacterIndex + 255<br />
End While<br />
<br />
sDecrypted &= Chr(iCharacterIndex)<br />
iKey += 1<br />
If iKey > (Key.Trim.Length - 1) Then iKey = 0<br />
Next<br />
Return sDecrypted<br />
<br />
End Function<br />
<br />
End Class
Regards
Steve Jowett
-------------------------
Sometimes a man who deserves to be looked down upon because he is a fool, is only despised only because he is an 'I.T. Consultant'
|
|
|
|
|
Hi Steve,
I strongly recommend you take a look at the System.Security.Cryptography namespace. "Homebrew" cryptographic algorithms are almost never secure, and are often vulnerable to the most trivial of cryptanalysis.
If you need to protect data then pick a reputable algorithm.
|
|
|
|
|
is it possible to use a WebBrowser control to open an existing web page and populate the text controls on the web page from VB.NET code? NOTE: the web page could be any existing page. For example www.google.com. Browse to Google and put some search text into the text control and press the Search button.
mcnewsxp
|
|
|
|
|
hi all,
as per my projects needs i am using checklistbox. now the requirement is to multiselect the items of checklistbox with shift or control key pressed, which is not possible with this control.
now i try to use the datagridview control as checklistbox.
- i hide the column header and row header
- the first column is datagridviewcheckboxcolumn
- the second column is datagridviewtextboxcolumn
for MOUSE handling
- i write my code on datagridview_cellclick event (that works perfectly as per need)
for KEYBOARED handling
- i write the same code on datagridview_cellvaluechanged event ( their the problem is )
when i check the checkbox, i need to change the other controls value accordingly. but the event fires when selection changed.
- i also try datagridview_selectionchange event but in that case i have to change the selection to get the values get change
does some one have any kind of idea to solve that problem.
thanks in advance
help everyone
|
|
|
|
|
I have been creating a custom control the base of which is an Panel and consists of a collection of Buttons.
The problem I am experiencing is when I try to add a button to the Button Collection, of the control, in the Form designer, an "Error creating window handle" error is generated.
If I add the button in code in the form Load event the button is added with no errors.
The offending code, which is appart of my Button class, is as follows :-
Protected Overrides Sub WndProc(ByRef m As Message)<br />
MyBase.WndProc(m)<br />
End Sub
On investigation the values of m are :-
LParam : 0
Msg : 133
Result : 0
WParam : 1
Steve Jowett
-------------------------
Sometimes a man who deserves to be looked down upon because he is a fool, is only despised only because he is an 'I.T. Consultant'
|
|
|
|
|
Strange one this, but I have resolved the problem. I say I resolved it; what I have done is Restarted my PC and hay-presto it's working as expected.
Steve Jowett
-------------------------
Sometimes a man who deserves to be looked down upon because he is a fool, is only despised only because he is an 'I.T. Consultant'
|
|
|
|
|
Hello,
my problem is: in my environment several EXCEL applications are running. I have to pick one specific application ( I have to check the application if it is the correct one).
EApp = Ctype(Marshal.GetActiveObject("Excel.Application"), Excel.Application)
returns only the first registered process with the correct name (and of course "my" application is usually not the first one). I need something like
"
Dim P() as Process = Process.GetProcessByName("Excel")
For i as integer = 0 To P.GetUpperBound(0)
EApp = Ctype(Marshal.GetActiveObject(P.ID), Excel.Application)
' application check here
Next
"
to find the second, third etc. application also.
Is there any idea?
Thank you
Carsten
|
|
|
|
|
Hi
I am having some issues with installation / deployment of a vb.net project, which are because of some OCM & Activex components
- I had originally made most of the application in vb6
- Then we converted the codes to vb.2005 express
- Then some more development was done
- Now the issue is that when we try to install the application on a client’s machine (which dose not have VB6 installed), the application dose not work
- After investing some time we found out that the issue is due to non availability of vb6 COM & Activex components
How do we add the reference of these COM component to the setup and export the DLL’s with it
Regards
Nishkarsh
-- modified at 6:09 Tuesday 13th November, 2007
|
|
|
|
|
Just add assembly in your setup project and register it on relative path. Hope this works
Regards
Pankaj Joshi
|
|
|
|