|
i search forum from examples but i did not find something to explicit to help. can you make some sugetions where to seek something or someone to explain step by step ?
thanks a lot for your help
|
|
|
|
|
When I search CodeProject with the keywords I provided earlier, I find several articles; the simplest is this one[^], however it is completely wrong about the cross-thread issue, you need to apply the link I provided.
Now go off and do your own research, I'm out of here.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
Here is what i have used; you might what to strip out chunks of the code, and tweak the formatting though, as the code below populates a list box with a formatted byte dump, 16 Bytes wide and limits the number of rows added.
Place in the top of the class
Private WithEvents port As IO.Ports.SerialPort
I have this in a 'Connect' button, the combobox contains the list of enumerated serial ports e.g. COM1, COM2 etc.
Try
port = My.Computer.Ports.OpenSerialPort(ComboBoxSerialPorts.Items.Item(ComboBoxSerialPorts.SelectedIndex))
Catch ex As Exception
MsgBox("Error Opening Port: " + ex.Message)
End Try
I have this is a 'Disconnect' button
If port.IsOpen Then
port.Close()
Else
MsgBox("Port is already closed.")
End If
This is the part that handles the bytes coming in, and format it into the 16 Bytes line and populates a label with current 16byte chunk, and then adds a completed 16byte chunk to the listbox and limits the number of lines etc.
''' <summary>
''' Delegate Method for the Cross Thread calls
''' </summary>
''' <param name="byteRead">The byte read from the port</param>
''' <remarks></remarks>
Delegate Sub UpdateByteReadDelegate(ByVal byteRead As Byte)
Private Sub UpdateBytesRead(ByVal readbyte As Byte)
'Only Log if Enabled
If MenuLoggingDisplayRawEnable.Checked = False Then Exit Sub
Static counter As Byte = 0
Static currentLine As String = ""
If labelCurrentRawLogLine.InvokeRequired Then
Dim d As New UpdateByteReadDelegate(AddressOf UpdateBytesRead)
Me.Invoke(d, New Object() {readbyte})
Else
'
currentLine = currentLine & Format(readbyte, "X2") + " "
labelCurrentRawLogLine.Text = currentLine
counter += 1
'Do we need a line wrap?
If counter = 16 Then
'Add a new line and reset counter
If MenuLoggingDisplayRawEnable.Checked Then
'Make Room for the incoming raw bytes log
Dim trimSize As Integer
If (ListRawLog.ClientSize.Height / ListRawLog.ItemHeight) > My.Settings.LoggingDisplayRawMaxRows Then
trimSize = (ListRawLog.ClientSize.Height / ListRawLog.ItemHeight)
Else
trimSize = My.Settings.LoggingDisplayRawMaxRows
End If
ListRawLog.BeginUpdate()
If ListRawLog.Items.Count + 1 >= trimSize Then
Do Until ListRawLog.Items.Count + 1 < trimSize
ListRawLog.Items.RemoveAt(0)
Loop
End If
End If
'Add the new raw bytes log
ListRawLog.Items.Add(currentLine)
ListRawLog.TopIndex = ListRawLog.Items.Count - 1
ListRawLog.EndUpdate()
labelCurrentRawLogLine.Text = ""
currentLine = ""
counter = 0
End If
End If
End Sub
This is where the bytes are received by the app
Private Sub port_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles port.DataReceived
UpdateBytesRead(Format(port.ReadByte, "X2"))
End Sub
As i say you can do all the stripping out of all the formatting stuff etc.
|
|
|
|
|
i will try and let you know
|
|
|
|
|
Hi,
I have finished my program, it all works brilliant in vb.net however when i try publishing it, it gives me a setup icon, i can click and "install" it but it comes up with unhandled exception when i try and run the program?!?!
I am using .txt files and have been putting them in the debug file however i think that is the problem?
Any help would be great as this is quite confusing!!
Cheers
|
|
|
|
|
The machine you are installing the application on, does it have .net installed?
|
|
|
|
|
yeah it does?? this is the machine i have been programming on? Even if i try and run the program from the bin it doesn't run it comes up with the unhandled error, however in vb.net. No probelms?
I didn't know if anybody else has had the same problems?
|
|
|
|
|
Put a Try Catch around on the form load event, make a message box pop up with ex.message and ex.stacktrace and see where your unhandled exception comes from (do this when you run from the bin, not the installation)
|
|
|
|
|
Apparently it can't find the.txt documents.
In vb.net i put them in the bin folder and that worked fine wtf??
as soon as its published it don't like them?
|
|
|
|
|
The way you read the txt files they where looking for them in the same directory as the executable file, this is because you did not use full path references to your text files and your program assumed they where in the same directory as the executable. You can solve this by creating your text files or checking for their existence before attempting to read/write to them.
|
|
|
|
|
i have been using
Dim value As String
value = Application.StartupPath
which has been showing like c:/desktop/test/test/bin/.txt file
you are probably right in what you are saying however, how to i change my code to what you are saying?
|
|
|
|
|
Are you using hardcoded paths?
have you tried copying the files from the release folder to a new folder somewhere e.g. on the desktop and also included the text files?
|
|
|
|
|
no i don't think so. I have been using the code
Dim value As String
value = Application.StartupPath
which shows up to the bin where the txt documetns are stored in
grrrrr lol
|
|
|
|
|
Just an update. THE PROGRAM NOW WORKS FROM THE BIN FOLDER (yipeeeeee)
however it still don't wanna be published (grrrrrrrr)
|
|
|
|
|
hi
Equivalent to the SQL code is?
Public Class Form1<br />
Public prgstr As String = Application.StartupPath<br />
Dim db As New ADODB.Connection<br />
Dim rs As New ADODB.Recordset<br />
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
db.Provider = "Microsoft.Jet.OLEDB.4.0"<br />
db.Open("db.mdb")<br />
LoadTV()<br />
End Sub<br />
Private Sub LoadTV()<br />
'On Error Resume Next<br />
rs.Open("[Folder]", db, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)<br />
Dim K, I, J, L As Integer<br />
Dim T, R, Pr As String<br />
rs.MoveFirst()<br />
For I = 1 To rs.RecordCount<br />
K = rs.Fields("Level").Value<br />
If J < K Then J = K<br />
If Not rs.EOF Then rs.MoveNext()<br />
Next<br />
rs.MoveFirst()<br />
For I = 0 To J<br />
rs.MoveFirst()<br />
For L = 1 To rs.RecordCount<br />
K = rs.Fields("Level").Value<br />
T = rs.Fields("head").Value '*** TEXT<br />
R = rs.Fields("ID").Value '*** key = F+id<br />
Pr = rs.Fields("Parent").Value<br />
<br />
<br />
If I = 0 And K = 0 Then<br />
' TV.Nodes.Add("F" & R, T, "bc", "bo")<br />
TV.Nodes.Add(R, T, "bc", "bo")<br />
Else<br />
If K = I Then<br />
' TV.Nodes.Find("F" & Pr, True)(0).Nodes.Add("F" & R, T, "gc", "go")<br />
TV.Nodes.Find(Pr, True)(0).Nodes.Add(R, T, "gc", "go")<br />
End If<br />
End If<br />
<br />
My.Application.DoEvents()<br />
If Not rs.EOF Then rs.MoveNext()<br />
<br />
Next<br />
' If Not rs.EOF Then rs.MoveNext()<br />
<br />
Next<br />
rs.Close()<br />
'rs.Open("Matn", db)<br />
'rs.MoveFirst()<br />
'For I = 1 To rs.RecordCount<br />
' K = rs.Fields("Folder").Value<br />
' R = rs.Fields("ID").Value<br />
' T = rs.Fields("Head").Value<br />
' TV.Nodes.Find("F" & K, True)(0).Nodes.Add("M" & R, T, "mc", "mo")<br />
' If Not rs.EOF Then rs.MoveNext()<br />
'Next<br />
<br />
'rs.Close()<br />
<br />
<br />
End Sub<br />
Sub CloseDB()<br />
rs.Close()<br />
db.Close()<br />
End Sub<br />
<br />
<br />
Private Sub TV_ItemDrag(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemDragEventArgs) Handles TV.ItemDrag<br />
DoDragDrop(e.Item, DragDropEffects.Move)<br />
<br />
End Sub<br />
<br />
<br />
<br />
Private Sub CreateRoot(ByVal Parrent As Integer, ByVal Level As Integer, ByVal PText As String)<br />
Dim strsql As String<br />
Dim cmd As New OleDbCommand<br />
Level += 1<br />
If Con.State = ConnectionState.Closed Then<br />
Con.Open()<br />
End If<br />
strsql = "insert into [Folder] ([Level],Head,Parent) values (" & Level & ",'" & PText & "', " & Parrent & ")"<br />
cmd.Connection = Con<br />
cmd.CommandText = strsql<br />
cmd.ExecuteNonQuery()<br />
Con.Close()<br />
<br />
End Sub
|
|
|
|
|
miladbiranvand wrote: Equivalent to the SQL code is?
What SQL? What is the problem? Please be more specific, what is the error message? Where is it happening (run in debug to find out values).
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
I put the first 1 vote in, and the reason is simple;
You didn't take the hint when you posted your messages over the weekend, or listen to the comments I fed back to you then.
Here you are again, Monday morning and posting this cr@p.
You seriously need to FIFO. before you ask it stands for Fit In or F*** Off.
Chris put these stickies at the top of the forum for a reason. You indicated you read them in one of your comments, but clearly you haven't.
Your post is just asking for someone to do your work for you. WISE UP! Nobody is going to help you at this rate.
DO YOU UNDERSTAND?
|
|
|
|
|
Several people have marked your post as a bad question without being brave enough to tell you why.
Well so have I and here's why.
1) It is in no way clear what it is that you want.
2) You have surrounded your code with <code></code> tags. You should have used <pre></pre> tags, as they will retain formatting when you paste code between them, or allow you to put in formatting (indentation etc) on previously pasted code. If you used the 'inline code' widget (above the Text: box) then use the 'code block' one instead.
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.”
|
|
|
|
|
im sorry.
example
in Access
dim da as new oledbdataadabtor
in sql
dim da as new sqldataadabtor
now
in Access
Dim db As New ADODB.Connection
Dim rs As New ADODB.Recordset
in sql = ????
-----
and
db.Provider = "Microsoft.Jet.OLEDB.4.0"
db.Open("db.mdb")
in sql = ????
in Access =
Private Sub LoadTV()
'On Error Resume Next
rs.Open("[Folder]", db, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)
Dim K, I, J, L As Integer
Dim T, R, Pr As String
rs.MoveFirst()
For I = 1 To rs.RecordCount
K = rs.Fields("Level").Value
If J < K Then J = K
If Not rs.EOF Then rs.MoveNext()
Next
rs.MoveFirst()
For I = 0 To J
rs.MoveFirst()
For L = 1 To rs.RecordCount
K = rs.Fields("Level").Value
T = rs.Fields("head").Value '*** TEXT
R = rs.Fields("ID").Value '*** key = F+id
Pr = rs.Fields("Parent").Value
If I = 0 And K = 0 Then
' TV.Nodes.Add("F" & R, T, "bc", "bo")
TV.Nodes.Add(R, T, "bc", "bo")
Else
If K = I Then
' TV.Nodes.Find("F" & Pr, True)(0).Nodes.Add("F" & R, T, "gc", "go")
TV.Nodes.Find(Pr, True)(0).Nodes.Add(R, T, "gc", "go")
End If
End If
My.Application.DoEvents()
If Not rs.EOF Then rs.MoveNext()
Next
' If Not rs.EOF Then rs.MoveNext()
Next
rs.Close()
'rs.Open("Matn", db)
'rs.MoveFirst()
'For I = 1 To rs.RecordCount
' K = rs.Fields("Folder").Value
' R = rs.Fields("ID").Value
' T = rs.Fields("Head").Value
' TV.Nodes.Find("F" & K, True)(0).Nodes.Add("M" & R, T, "mc", "mo")
' If Not rs.EOF Then rs.MoveNext()
'Next
'rs.Close()
End Sub
in sql =???
Do you UNDERSTAND?
|
|
|
|
|
You still haven't come up with a specific problem you just want someone to rewrite the code to to use an SQL data provider instead of a JET provider.
I suggest that you break down your code into its functional blocks, and go read the documentation relating to System.Data namespace and the classes within, such as the SQLConnection, SQLCommand, SQLDataAdapter, SQLDataReader etc.
|
|
|
|
|
Does anyone with a friend ?
Me into your code by .
thank you.
|
|
|
|
|
miladbiranvand wrote: Does anyone with a friend ?
Me into your code by .
thank you
What? That's jibberish.
Steve Jowett
-------------------------
Real programmers don't comment their code. If it was hard to write, it should be hard to read.
|
|
|
|
|
Take a look at this[^].
It is a tutorial on the process of converting ADO to ADO.Net.
Give it a try, and come back with specific questions about anything you cannot get to work.
Good Luck!
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.”
|
|
|
|
|
|
code is
Public Class Form1
Public DsCenter As New DataSet
Public Count As Integer = 1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
FillDsCenter()
LoadTV()
End Sub
Public Sub FillDsCenter()
Dim StrSql As String
Dim da As New OleDbDataAdapter
If Con.State = ConnectionState.Closed Then
Con.Open()
End If
StrSql = "SELECT * FROM Folder"
da = New OleDbDataAdapter(StrSql, Con)
DsCenter.Clear()
da.Fill(DsCenter, "tbl")
Con.Close()
End Sub
Private Sub LoadTV()
Dim K, I, J, L As Integer '1
Dim T, R, Pr As String '2
Count = 1 '3
For I = 1 To DsCenter.Tables("tbl").Rows.Count '4
K = DsCenter.Tables("tbl").Rows(Count - 1).Item("Level") '5
If J < K Then J = K '6
If Not (Count = DsCenter.Tables("tbl").Rows.Count) Then Count += 1
Next 'ok
Count = 1 'ok
For I = 0 To J 'ok
Count = 1 'ok
For L = 1 To DsCenter.Tables("tbl").Rows.Count 'ok
K = DsCenter.Tables("tbl").Rows(Count - 1).Item("Level") 'ok
T = DsCenter.Tables("tbl").Rows(Count - 1).Item("head") 'ok
R = DsCenter.Tables("tbl").Rows(Count - 1).Item("ID") 'ok
Pr = DsCenter.Tables("tbl").Rows(Count - 1).Item("Parent") 'ok
If I = 0 And K = 0 Then 'ok
TV.Nodes.Add(R, T, "bc", "bo") 'ok
Else 'ok
If K = I Then 'ok
TV.Nodes.Find(Pr, True)(0).Nodes.Add(R, T, "gc", "go") 'ok
End If 'ok
End If 'ok
If Count <> DsCenter.Tables("tbl").Rows.Count Then Count += 1
Next
Next
'*** table matn
'Count = 1
'For I = 1 To DsCenter.Tables("tbl").Rows.Count
' K = DsCenter.Tables("tbl").Rows(Count - 1).Item("Folder")
' R = DsCenter.Tables("tbl").Rows(Count - 1).Item("ID")
' T = DsCenter.Tables("tbl").Rows(Count - 1).Item("Head")
' TV.Nodes.Find("F" & K, True)(0).Nodes.Add("M" & R, T, "mc", "mo")
' If Count <> DsCenter.Tables("tbl").Rows.Count Then Count += 1
'Next
End Sub
|
|
|
|
|