|
waner michaud wrote: I want the loginForm to reload so the user can login If the main-form closes, (as in, "all forms"), the application closes.
That raises another problem; how does one close your application? By closing the loginform? If yes, then the login-form would be the mainform, hidden when someone logs in, closes if someone cancels the login.
Alternatively, you can control the exit of the application by adding an explicit entry point (or does the IDE generate one nowadays?) Add a module like below;
Module Module1
Sub Main()
Using loginForm As New LoginForm()
While loginForm.ShowDialog() <> DialogResult.Cancel
Using mainForm As New MainForm()
MainForm.ShowDialog()
End Using
End While
End Using
End Sub
End Module Next, open the projects' properties (right click in solution explorer, or using the main menu), go to tab "Application" and play a bit with the "Shutdown mode" setting. Uncheck "Enable application framework", and change the "Startup object" (on the same tab, was called "Startup form" before the uncheck) to "Module1".
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hello again,
Thanks for your response.
I have an exit button that closes the application completely. But what I want is to log out button that will log out the current user and allow a new user to log in.
Basically that's what I want to accomplish.
Thanks again
|
|
|
|
|
That's what the example does, albeit you'll need to modify your own app.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hello all i am new to this language and i have ported my code from vb6 to vb.net and getting this issue.
I am getting the error in this code line=
mvarTimer = frmMain.Controls.Add("VB.Timer", strTemp)
I dont understand how to fix this issue ,i am helpless
Any one here please help me i will be thankful to you
<pre> Public Function fnInitializeTimer() As Object
Dim strTemp As String
'we need unique name for timer hence appended the number of control to the name
'UPGRADE_WARNING: Controls method Controls.Count has a new behavior. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6BA9B8D2-2A32-4B6E-8D36-44949974A5B4"'
strTemp = "Timer" & frmMain.Controls.Count() + 1
'Initialize the timer variable
'UPGRADE_ISSUE: Controls method Controls.Add was not upgraded. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
'mvarTimer = frmMain.Controls.Add("VB.Timer", strTemp)
mvarTimer = frmMain.Controls.Add("VB.Timer", strTemp)
mvarTimer.Enabled = False
End Function
|
|
|
|
|
|
If you've got this many errors it can be considered a barometer of how badly the original code was written.
The best way to solve this problem is to scrap it all and rewrite. That way, you're not forcing VB.NET to try and emulate the bad behavior of VB6 and the code written in it.
|
|
|
|
|
Hello guys i have converted one old vb6 code to vb .net and i getting the above mentioned error. Please help me i don't know about this. I will be thankful to you!
here is the code which is showing the error
frmMain.listStringReplace.Items.Item(nItemIdex).SubItems.Add(1, , strStringToBeReplaced)
frmMain.listStringReplace.Items.Item(nItemIdex).SubItems.Add(2, , strImagePath)
If frmMain.optReplace.Checked = True Then
frmMain.listStringReplace.Items.Item(nItemIdex).SubItems.Add(3, , "Replace")
ElseIf frmMain.optAppend.Checked = True Then
<big>frmMain.listStringReplace.Items.Item(nItemIdex).SubItems.Add(3, , "Append")</big>
ElseIf frmMain.optPrePend.Checked = True Then
frmMain.listStringReplace.Items.Item(nItemIdex).SubItems.Add(3, , "Prepend")
End If
|
|
|
|
|
|
Thanks for the reply but can you please suggest me few lines of code as i have visited that page but still not able to correct my error
|
|
|
|
|
Look at your call to Add and you can see that it tries to use 3 parameters SubItems.Add(1, , strStringToBeReplaced) , even though the second one is missing. Now look at the documentation and you can see that there is no overload of the Add method that takes this number. You can use one of
Add(ListViewItem.ListViewSubItem)
Add(String)
Add(String, Color, Color, Font)
If your call does not match one of these methods then the compiler will reject it.
|
|
|
|
|
|
Hi All,
Please find my code below to read the output of two independent temperatures streams.
The form now works well but I cannot close the form when I use the button btnDisconnect_Click at the bottom of the code. The only way I can stop the code is by the stop debugging.
Please can you help
Thank you in advance
Nevjc
Imports System.Drawing.Drawing2D
Imports System.IO.Ports
Public Class Form1
Dim bmp1 As Bitmap = New Bitmap(165, 550)
Dim temperature1 As Double = 10
Dim temperature2 As Double = 10
Dim WithEvents sp As New SerialPort
Private Sub pictherm1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles pictherm1.Paint
Dim g As Graphics = e.Graphics
g.Clear(Color.White)
If temperature1 > 100 Then temperature1 = 100
g.FillRectangle(Brushes.Green, 48, 525 - CInt(temperature1 * 5), 10, CInt(temperature1 * 5))
If temperature2 > 100 Then temperature2 = 100
g.FillRectangle(Brushes.Green, 108, 525 - CInt(temperature2 * 5), 10, CInt(temperature2 * 5))
g.DrawLine(Pens.Black, 60, 525, 60, 25)
g.DrawLine(Pens.Black, 105, 525, 105, 25)
For i As Integer = 25 To 525 Step 5
g.DrawLine(Pens.Black, 50, i, 60, i)
g.DrawLine(Pens.Black, 105, i, 115, i)
Next
Dim f As Font = New Font("Verdana", 10, FontStyle.Regular)
Dim scale As Integer
For i As Integer = 525 To 25 Step -25
g.DrawLine(Pens.Black, 45, i, 60, i)
g.DrawLine(Pens.Black, 105, i, 120, i)
scale = (525 - i) / 5
g.DrawString(Str(scale), f, Brushes.Black, 65, i - 8)
Next
End Sub
Private Sub btnConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConnect.Click
Try
sp.BaudRate = "9600"
sp.PortName = "COM5"
sp.Open()
If sp.IsOpen Then
btnConnect.Visible = False
btnDisconnect.Visible = True
End If
Catch
sp.Close()
End Try
End Sub
Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
If sp.IsOpen() Then
MessageBox.Show("Disconnect before closing")
e.Cancel = True
End If
End Sub
Delegate Sub myMethodDelegate1(ByVal [text] As String)
Dim myDelegate1 As New myMethodDelegate1(AddressOf ProcessReading1)
Private Sub SerialPort_DataReceived1(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles sp.DataReceived
Dim str1 As String = sp.ReadLine()
Dim firststr As String = Mid(str1, 1, 4)
Invoke(myDelegate1, firststr)
End Sub
Sub ProcessReading1(ByVal input As String)
If IsNumeric(input) Then
temperature1 = CDbl(input)
lblLeft.Text = CDbl(temperature1)
pictherm1.Refresh()
End If
End Sub
Delegate Sub myMethodDelegate2(ByVal [text] As String)
Dim myDelegate2 As New myMethodDelegate2(AddressOf ProcessReading2)
Private Sub SerialPort_DataReceived2(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles sp.DataReceived
Dim str2 As String = sp.ReadLine()
Dim secondstr As String = Mid(str2, 6, 5)
Invoke(myDelegate2, secondstr)
End Sub
Sub ProcessReading2(ByVal input As String)
If IsNumeric(input) Then
temperature2 = CDbl(input)
lblRight.Text = CDbl(temperature2)
lblTotal.Text = CDbl(temperature1 + temperature2)
lblDiff.Text = CDbl(temperature1 - temperature2)
pictherm1.Refresh()
End If
End Sub
Private Sub btnDisconnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisconnect.Click
Try
sp.Close()
btnConnect.Visible = True
btnDisconnect.Visible = False
Exit Sub
Catch
MessageBox.Show("Some kind of problem.")
End Try
End Sub
End Class
|
|
|
|
|
What about this.Close(); or Application.Exit(); ?
|
|
|
|
|
Hi Berhard,
Thankyou for the suggestion. Both those work when you have just opened the form but as soon as you start reading the serial port they dont work. It appears that the infomation from the serial port is holding the form open.
Any other suggestions?
Regards
Nevjc
|
|
|
|
|
I would try the following modifications to the DataReceived event handlers
Private Sub SerialPort_DataReceived1(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles sp.DataReceived
Try
Dim str1 As String = sp.ReadLine()
Dim firststr As String = Mid(str1, 1, 4)
Invoke(myDelegate1, firststr)
BeginInvoke(myDelegate1, firststr)
Catch ioex As IOException
System.Diagnostics.Debug.Print("IOException {0}", ioex.Message)
EndTry
End Sub
If ReadLine is blocked waiting for data then issuing a Close request on the SerialPort will cause an IOException to be thrown with the message "Serial port is Closed". I don't know if that will be causing a problem but the Try.. Catch will let you see what's happening.
Replacing Invoke with BeginInvoke can only do good as it will allow the UI thread to invoke the delegate when it is not busy. If the problem is a deadlock then this change will definitely help.
Alan.
|
|
|
|
|
Hi Alan,
Thanks for that.
I have changed the Invoke to BeginInvoke and there is an improvement in operation ie the btnconnect button returns as it should occasionally.
The form also occasionally closes and themessage returned is "IO Eception was unhandled" is reported and the Dim str1 As String =sp.Readline() is yellowed out.
Does this help?
Regards Nevjc
|
|
|
|
|
Premise that I do not have much experience with visual basic!
I need to make a chart from a csv file that is structured like this:
"VarName", "TimeString", "Temperature", "Validity", "Time_ms"
"var_1", "04/02/2014 04:40:29", 115.5, 1, 41,731,194,780.0926
"var_3", "04/02/2014 04:42:37", 27.4, 1, 41,731,196,261.5741
"var_2", "04/02/2014 04:42:37", 83.2, 1, 41,731,196,261.5741
"var_1", "04/02/2014 04:42:37", 115.8, 1, 41,731,196,261.5741
note that "VarName" are listed in no particular order.
What I would like is to be able to choose the "VarName" via a ComboBox and via a DateTimePicker the day, so as to produce a chart with "TimeString" on the X axis and "Temperature" on Y.
If can be done you can help me, I dont know where to start.
Sorry for my english :-O
Thank you!
|
|
|
|
|
Member 10735492 wrote: I dont know where to start. Given your first sentence, I would suggest studying more VB.NET, and some of the articles at http://www.codeproject.com/KB/vb/[^].
|
|
|
|
|
Member 10735492 wrote: What I would like is to be able to choose the "VarName" via a ComboBox and via a DateTimePicker the day, so as to produce a chart with "TimeString" on the X axis and "Temperature" on Y. You'd start by finding a tutorial on using the chart. I don't know whether you're using WinForms, ASP, WPF or Gtk. But assuming your using either WinForms or ASP, you'd start here[^].
I'd also recommend against charting directly from a CSV; the file-format is meant for exports, not as a datastore that one would query often.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hell every one
I converted my vb6 project to vb.net and having this error.
My code is
Public Function CenterMessageBox(ByRef frmHwnd As Integer) As Object
Dim lInstance As Integer
Dim lThreadID As Integer
lInstance = GetWindowLong(frmHwnd, GWL_HINSTANCE)
lThreadID = GetCurrentThreadId()
plMsgHook = SetWindowsHookEx(WH_CBT, AddressOf CenterMsgCallBack, lInstance, lThreadID)
End Function
and
Private Function CenterMsgCallBack(ByVal lMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Dim typFormRect As RECT
Dim typRectMsg As RECT
Dim lxPos, lyPos As Integer
If lMsg = HCBT_ACTIVATE Then
GetWindowRect(frmMain.Handle.ToInt32, typFormRect)
GetWindowRect(wParam, typRectMsg)
lxPos = (typFormRect.Left_Renamed + (typFormRect.Right_Renamed - typFormRect.Left_Renamed) / 2) - ((typRectMsg.Right_Renamed - typRectMsg.Left_Renamed) / 2)
lyPos = (typFormRect.Top + (typFormRect.Bottom - typFormRect.Top) / 2) - ((typRectMsg.Bottom - typRectMsg.Top) / 2)
SetWindowPos(wParam, 0, lxPos, lyPos, 0, 0, SWP_NOSIZE Or SWP_NOZORDER Or SWP_NOACTIVATE)
UnhookWindowsHookEx(plMsgHook)
End If
CenterMsgCallBack = False
End Function
Please tell me what to do. I don't know this programming language and i have searched the answer of it but not getting how to implememt. Please help I will be thankful to you
|
|
|
|
|
That's some really old code - I'm guessing it came from this[^], which says it was written for VB5.
The immediate problem is that you're trying to pass a callback delegate as a Integer . You can't do that in VB.NET; you have to pass it as a delegate instead.
A lot of the parameters that you're passing as Integer need to be IntPtr to work properly in 64-bit applications. You can usually get a good declaration for the P/Invoke methods from pinvoke.net[^].
The code also never calls CallNextHookEx , which you're supposed to call from the hook callback method.
The following code should work:
Imports System.Runtime.InteropServices
Module MsgBoxHelper
<StructLayout(LayoutKind.Sequential)> _
Private Structure RECT
Public ReadOnly Left As Integer
Public ReadOnly Top As Integer
Public ReadOnly Right As Integer
Public ReadOnly Bottom As Integer
End Structure
Private Delegate Function HookProc(ByVal code As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
<DllImport("user32.dll", SetLastError:=True)> _
Private Function SetWindowsHookEx(ByVal hookType As Integer, ByVal lpfn As HookProc, ByVal hMod As IntPtr, ByVal dwThreadId As Integer) As IntPtr
End Function
<DllImport("user32.dll")> _
Private Function CallNextHookEx(ByVal hhk As IntPtr, ByVal nCode As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
End Function
<DllImport("user32.dll", SetLastError:=True)> _
Private Function UnhookWindowsHookEx(ByVal hhk As IntPtr) As Boolean
End Function
<DllImport("user32.dll", SetLastError:=True)> _
Private Function GetWindowLong(ByVal hWnd As IntPtr, ByVal nIndex As Integer) As IntPtr
End Function
<DllImport("kernel32.dll")> _
Private Function GetCurrentThreadId() As Integer
End Function
<DllImport("user32.dll")> _
Private Function GetWindowRect(ByVal hWnd As IntPtr, ByRef lpRect As RECT) As Boolean
End Function
<DllImport("user32.dll", SetLastError:=True)> _
Private Function SetWindowPos(ByVal hWnd As IntPtr, ByVal hWndInsertAfter As IntPtr, _
ByVal X As Integer, ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal uFlags As Integer) As Boolean
End Function
Private Const GWL_HINSTANCE As Integer = -6
Private Const HCBT_ACTIVATE As Integer = 5
Private Const SWP_NOSIZE As Integer = &H1
Private Const SWP_NOZORDER As Integer = &H4
Private Const SWP_NOACTIVATE As Integer = &H10
Private Const WH_CBT As Integer = 5
Private theForm As IWin32Window
Private plMsgHook As IntPtr
Public Sub CenterMessageBox(ByVal parentForm As IWin32Window)
If parentForm Is Nothing Then
Throw New ArgumentNullException("parentForm")
End If
If plMsgHook <> IntPtr.Zero Then
Throw New InvalidOperationException("The hook is already installed.")
End If
theForm = parentForm
Dim lInstance As IntPtr = GetWindowLong(parentForm.Handle, GWL_HINSTANCE)
Dim lThreadID As Integer = GetCurrentThreadId()
plMsgHook = SetWindowsHookEx(WH_CBT, AddressOf CenterMsgCallBack, lInstance, lThreadID)
End Sub
Private Function CenterMsgCallBack(ByVal code As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
If code = HCBT_ACTIVATE Then
Dim typFormRect As RECT
Dim typMsgRect As RECT
Dim lxPos As Integer, lyPos As Integer
GetWindowRect(theForm.Handle, typFormRect)
GetWindowRect(wParam, typMsgRect)
lxPos = CInt((typFormRect.Left + (typFormRect.Right - typFormRect.Left) / 2) - ((typMsgRect.Right - typMsgRect.Left) / 2))
lyPos = CInt((typFormRect.Top + (typFormRect.Bottom - typFormRect.Top) / 2) - ((typMsgRect.Bottom - typMsgRect.Top) / 2))
SetWindowPos(wParam, IntPtr.Zero, lxPos, lyPos, 0, 0, SWP_NOSIZE Or SWP_NOZORDER Or SWP_NOACTIVATE)
UnhookWindowsHookEx(plMsgHook)
plMsgHook = IntPtr.Zero
theForm = Nothing
End If
Return CallNextHookEx(IntPtr.Zero, code, wParam, lParam)
End Function
End Module
To call it:
CenterMessageBox(Me)
MessageBox.Show("This is a centered Message Box")
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hello !
I have a binding source to entity :
MyBindingsource.datasource=(From t in context.Mytable Select t.id , t.vl1 , t.vl2).Tolist
Now , I try to change a value like this :
Mybindingsource.Current.vl1=25
I get a n error :
An unhandled exception of type 'System.MissingMemberException' occurred in Microsoft.VisualBasic.dll
Additional information: Property 'vl1' is ReadOnly.
Why I get this error ? What can I do ?
Thank you !
|
|
|
|
|
vl1 is a property in a class. It does not have a set accessor, i.e. your property looks something like
public int vl1
{
get { return ...; }
}
insetad of
public int vl1
{
get { return ...; }
set { ...; }
}
|
|
|
|
|
Why does not have a set ?
Because , if I try the following code everything works ok :
MyBindingsource.datas
ource=(From t in context.Mytable Select t).Tolist
Why this :
MyBindingsource.datasource=(From t in context.Mytable Select t.id , t.vl1 , t.vl2).Tolist doesn't work ?
Thank you !
|
|
|
|
|
dilkonika wrote: Because , if I try the following code everything works ok : That's different code; the setter isn't used there. The code below, as you posted, would raise that exception - if it is a read-only property.
Mybindingsource.Current.vl1=25
dilkonika wrote: MyBindingsource.datasource=(From t in context.Mytable Select t.id , t.vl1 , t.vl2).Tolist Does it throw the SAME exception? I don't see it assigning anything to vl1 and doubt that it will throw the same error.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|