|
Apologies for the shouting but this is important.
When answering a question please:
- Read the question carefully
- Understand that English isn't everyone's first language so be lenient of bad spelling and grammar
- If a question is poorly phrased then either ask for clarification, ignore it, or mark it down. Insults are not welcome
- If the question is inappropriate then click the 'vote to remove message' button
Insults, slap-downs and sarcasm aren't welcome. Let's work to help developers, not make them feel stupid.
cheers,
Chris Maunder
The Code Project Co-founder
Microsoft C++ MVP
|
|
|
|
|
For those new to message boards please try to follow a few simple rules when posting your question.- Choose the correct forum for your message. Posting a VB.NET question in the C++ forum will end in tears.
- Be specific! Don't ask "can someone send me the code to create an application that does 'X'. Pinpoint exactly what it is you need help with.
- Keep the subject line brief, but descriptive. eg "File Serialization problem"
- Keep the question as brief as possible. If you have to include code, include the smallest snippet of code you can.
- Be careful when including code that you haven't made a typo. Typing mistakes can become the focal point instead of the actual question you asked.
- Do not remove or empty a message if others have replied. Keep the thread intact and available for others to search and read. If your problem was answered then edit your message and add "[Solved]" to the subject line of the original post, and cast an approval vote to the one or several answers that really helped you.
- If you are posting source code with your question, place it inside <pre></pre> tags. We advise you also check the "Encode "<" (and other HTML) characters when pasting" checkbox before pasting anything inside the PRE block, and make sure "Use HTML in this post" check box is checked.
- Be courteous and DON'T SHOUT. Everyone here helps because they enjoy helping others, not because it's their job.
- Please do not post links to your question into an unrelated forum such as the lounge. It will be deleted. Likewise, do not post the same question in more than one forum.
- Do not be abusive, offensive, inappropriate or harass anyone on the boards. Doing so will get you kicked off and banned. Play nice.
- If you have a school or university assignment, assume that your teacher or lecturer is also reading these forums.
- No advertising or soliciting.
- We reserve the right to move your posts to a more appropriate forum or to delete anything deemed inappropriate or illegal.
cheers,
Chris Maunder
The Code Project Co-founder
Microsoft C++ MVP
|
|
|
|
|
Can someone help please?
I have been building a GUI to connect up to Arduino Mega Mini Pro board to run CNC GRBL. where, I am only utilising the GRBL to run B & C rotational axis (yes, the GRBL is 5 axis library). So, the GRBL compiles and loads up onto the Mega Mini Pro, just fine.
The GUI is all good (I think) with its own little connection form that allows me to choose port and baud rate and connect.
I load up the relevant G-Code and before I can press the run button, the GRBL seems to be receiving the instruction as soon as I load it up on the text display. also the highlight, meant to move one line at the time, but that isn't whats happening!
Also, the Realtime display for the B & C aren't displaying anything at all! all though I can see on the output window of the VB2013, that GUI is talking to GRBL and GRBL is talking back as well as the display data is updated and sent back by GRBL, yet not displayed on the GUI!
Also the buttons for +B,-B,+C,-C aren't working well either. meaning, there are intermittent responds from them, even though I've added delays for time to respond!
not sure what I can do to make this GUI work.
Can you help please?
I am attaching the code here for both main form and the connection sub form, how do I post the image of the GUI?
for the moment, I am not attempting anything with MPG.
Main GUI:
Imports System.IO.Ports
Imports System.IO
Imports System.Windows.Forms
Public Class CNC4thand5thAxisControlGUI
Private WithEvents serialPort As New SerialPort()
Private gCodeLines As List(Of String)
Private currentLineIndex As Integer = 0
Private isPaused As Boolean = False
Private bPosition As Double = 0.0
Private cPosition As Double = 0.0
Private incomingDataBuffer As String = String.Empty
Private isExecutionComplete As Boolean = False
Private isGRBLReady As Boolean = True ' Indicates if GRBL is ready for next command
Private WithEvents tmrPosition As New Timer() ' Timer for position updates
' Initialize and start the timer for real-time position updates
Private Sub tmrPosition_Tick(sender As Object, e As EventArgs) Handles tmrPosition.Tick
If serialPort.IsOpen Then
serialPort.WriteLine("?") ' Send status request to GRBL
End If
End Sub
' Form Load event
Private Sub CNC4thand5thAxisControlGUI_Load(sender As Object, e As EventArgs) Handles MyBase.Load
gCodeLines = New List(Of String)
serialPort.BaudRate = 115200
serialPort.DataBits = 8
serialPort.Parity = Parity.None
serialPort.StopBits = StopBits.One
serialPort.Handshake = Handshake.None
' Timer setup
tmrPosition.Interval = 500 ' Poll every 500ms
tmrPosition.Start() ' Start the timer to poll GRBL for position updates
End Sub
' Clear Code Button
Private Sub btnClearCode_Click(sender As Object, e As EventArgs) Handles btnClearCode.Click
txtGCode.Clear()
gCodeLines.Clear()
currentLineIndex = 0
isExecutionComplete = False
End Sub
' Load G-Code
Private Sub btnLoad_Click(sender As Object, e As EventArgs) Handles btnLoad.Click
Dim openFileDialog As New OpenFileDialog
openFileDialog.Filter = "G-Code Files (*.txt)|*.txt|All Files (*.*)|*.*"
If openFileDialog.ShowDialog() = DialogResult.OK Then
gCodeLines = File.ReadAllLines(openFileDialog.FileName).ToList()
txtGCode.Text = String.Join(Environment.NewLine, gCodeLines)
Console.WriteLine("G-code loaded. Total lines: " & gCodeLines.Count.ToString())
End If
End Sub
' Run G-Code
Private Sub btnRun_Click(sender As Object, e As EventArgs) Handles btnRun.Click
If serialPort.IsOpen Then
If gCodeLines.Count = 0 Then
MessageBox.Show("No G-code loaded. Please load a G-code file.")
Return
End If
isPaused = False
currentLineIndex = 0
isExecutionComplete = False
SendNextGCodeLine()
Else
MessageBox.Show("Serial port is not open. Please connect to the Arduino.")
End If
End Sub
' Send the next line of G-Code
Private Sub SendNextGCodeLine()
If currentLineIndex < gCodeLines.Count AndAlso Not isPaused Then
Dim line As String = gCodeLines(currentLineIndex).Trim()
If Not String.IsNullOrEmpty(line) Then
' Send the line to GRBL
serialPort.WriteLine(line & vbLf)
' Log the sent line in the output console
Console.WriteLine("Sending G-code line " & (currentLineIndex + 1) & ": " & line)
' Highlight the line being sent
HighlightCurrentLine(currentLineIndex)
End If
ElseIf currentLineIndex >= gCodeLines.Count Then
isExecutionComplete = True ' Mark execution as complete
Console.WriteLine("No more G-code lines to send.")
End If
End Sub
' Highlight G-Code Line
Private Sub HighlightCurrentLine(lineIndex As Integer)
If lineIndex >= 0 AndAlso lineIndex < txtGCode.Lines.Length Then
txtGCode.Select(0, txtGCode.TextLength)
txtGCode.SelectionBackColor = Color.White
Dim start As Integer = txtGCode.GetFirstCharIndexFromLine(lineIndex)
Dim length As Integer = txtGCode.Lines(lineIndex).Length
txtGCode.Select(start, length)
txtGCode.SelectionBackColor = Color.Cyan
txtGCode.ScrollToCaret()
End If
End Sub
' Connect to Serial Port
Private Sub btnConnect_Click(sender As Object, e As EventArgs) Handles btnConnect.Click
Dim connectForm As New ConnectForm
If connectForm.ShowDialog() = DialogResult.OK Then
serialPort.PortName = connectForm.SelectedPort
serialPort.BaudRate = connectForm.SelectedBaudRate
Try
serialPort.Open()
MessageBox.Show("Connected to " & connectForm.SelectedPort & " at " & connectForm.SelectedBaudRate & " baud rate.")
Catch ex As Exception
MessageBox.Show("Error opening serial port: " & ex.Message)
End Try
End If
End Sub
' Disconnect Serial Port
Private Sub btnDisconnect_Click(sender As Object, e As EventArgs) Handles btnDisconnect.Click
If serialPort.IsOpen Then
serialPort.Close()
MessageBox.Show("Serial port disconnected.")
End If
End Sub
' Handle response from GRBL and send the next G-code line
Private Sub serialPort_DataReceived(sender As Object, e As SerialDataReceivedEventArgs) Handles SerialPort.DataReceived
Try
incomingDataBuffer &= serialPort.ReadExisting()
If incomingDataBuffer.Contains(vbLf) Then
Dim lines As String() = incomingDataBuffer.Split({vbLf}, StringSplitOptions.RemoveEmptyEntries)
For Each response As String In lines
Me.Invoke(Sub() Console.WriteLine("GRBL Response: " & response))
' If 'ok' is received, move to the next line or unlock jogging
If response.Contains("ok") Then
Me.Invoke(Sub()
isGRBLReady = True ' Ready for the next jog or G-code command
IncrementLineAndSend() ' Send the next line if in G-code run
End Sub)
End If
' Handle GRBL status responses (for position updates)
If response.StartsWith("<") Then
Me.Invoke(Sub() ParsePosition(response)) ' Parse position feedback from GRBL
End If
Next
' Clear the buffer after processing the data
incomingDataBuffer = String.Empty
End If
Catch ex As Exception
Me.Invoke(Sub() MessageBox.Show("Error reading from serial port: " & ex.Message))
End Try
End Sub
' Increment the current line index and send the next G-code line
Private Sub IncrementLineAndSend()
If currentLineIndex < gCodeLines.Count - 1 Then
currentLineIndex += 1 ' Move to the next line
SendNextGCodeLine() ' Send the next line
Else
isExecutionComplete = True ' No more lines to send
Console.WriteLine("All G-code lines have been sent.")
End If
End Sub
' Parse GRBL Position
Private Sub ParsePosition(response As String)
Try
' Log the full GRBL response for debugging purposes
Console.WriteLine("Parsing GRBL Position: " & response)
Dim parts As String() = response.Split("|"c)
For Each part As String In parts
If part.StartsWith("B:") Then
bPosition = Convert.ToDouble(part.Replace("B:", "").Trim())
Console.WriteLine("Parsed B Position: " & bPosition)
ElseIf part.StartsWith("C:") Then
cPosition = Convert.ToDouble(part.Replace("C:", "").Trim())
Console.WriteLine("Parsed C Position: " & cPosition)
End If
Next
' Update the labels with real-time positions
Me.Invoke(Sub()
lblBPosition.Text = "B Pos: " & bPosition.ToString("F3")
lblCPosition.Text = "C Pos: " & cPosition.ToString("F3")
End Sub)
Catch ex As Exception
' Log the error to identify parsing issues
Console.WriteLine("Error parsing GRBL position data: " & ex.Message)
End Try
End Sub
' Manual Jogging for B and C axes with GRBL readiness check
Private Sub btnJogBPositive_Click(sender As Object, e As EventArgs) Handles btnJogBPositive.Click
If serialPort.IsOpen AndAlso isGRBLReady Then
serialPort.WriteLine("G91 G0 B10" & vbLf) ' Move B+10 degrees relative
Console.WriteLine("Jogging B+10 degrees.")
isGRBLReady = False ' Wait for "ok" before allowing next command
End If
End Sub
Private Sub btnJogBNegative_Click(sender As Object, e As EventArgs) Handles btnJogBNegative.Click
If serialPort.IsOpen AndAlso isGRBLReady Then
serialPort.WriteLine("G91 G0 B-10" & vbLf) ' Move B-10 degrees relative
Console.WriteLine("Jogging B-10 degrees.")
isGRBLReady = False
End If
End Sub
Private Sub btnJogCPositive_Click(sender As Object, e As EventArgs) Handles btnJogCPositive.Click
If serialPort.IsOpen AndAlso isGRBLReady Then
serialPort.WriteLine("G91 G0 C10" & vbLf) ' Move C+10 degrees relative
Console.WriteLine("Jogging C+10 degrees.")
isGRBLReady = False
End If
End Sub
Private Sub btnJogCNegative_Click(sender As Object, e As EventArgs) Handles btnJogCNegative.Click
If serialPort.IsOpen AndAlso isGRBLReady Then
serialPort.WriteLine("G91 G0 C-10" & vbLf) ' Move C-10 degrees relative
Console.WriteLine("Jogging C-10 degrees.")
isGRBLReady = False
End If
End Sub
' Close Serial Port
Private Sub CNC4thand5thAxisControlGUI_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
If serialPort.IsOpen Then serialPort.Close()
End Sub
End Class
Connection sub form:
Imports System.IO.Ports
Public Class ConnectForm
Public Property SelectedPort As String
Public Property SelectedBaudRate As Integer
Private Sub ConnectForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' Populate available COM ports
cmbPort.Items.AddRange(SerialPort.GetPortNames())
' Populate Baud rate options
cmbBaudRate.Items.Add("9600")
cmbBaudRate.Items.Add("115200") ' Standard for GRBL
cmbBaudRate.Items.Add("250000")
End Sub
' OK button handler
Private Sub btnOK_Click(sender As Object, e As EventArgs) Handles btnOK.Click
' Set selected port and baud rate
If cmbPort.SelectedItem IsNot Nothing AndAlso cmbBaudRate.SelectedItem IsNot Nothing Then
SelectedPort = cmbPort.SelectedItem.ToString()
SelectedBaudRate = Convert.ToInt32(cmbBaudRate.SelectedItem.ToString())
Me.DialogResult = DialogResult.OK
Me.Close()
Else
MessageBox.Show("Please select both a COM port and Baud rate.")
End If
End Sub
' Cancel button handler
Private Sub btnCancel_Click(sender As Object, e As EventArgs) Handles btnCancel.Click
Me.DialogResult = DialogResult.Cancel
Me.Close()
End Sub
End Class
|
|
|
|
|
Public Sub FetchDataByName(customerName As String)
' Show debugging message
MessageBox.Show("FetchDataByName called with Name: " & customerName)
' Replace with your actual MySQL connection details
Dim connectionString As String = "Server=localhost;Port=3306;Database=MyData;Uid=asmgssl;Pwd=0786;"
Dim query As String = "SELECT * FROM customer WHERE cname = @cname"
Try
Using connection As New MySqlConnection(connectionString)
connection.Open()
Using command As New MySqlCommand(query, connection)
command.Parameters.AddWithValue("@cname", customerName)
Using reader As MySqlDataReader = command.ExecuteReader()
' Process query result
If reader.Read() Then
' Example: Retrieve data and show in message box
Dim customerId As Integer = reader.GetInt32("id")
Dim customerAddress As String = reader.GetString("address")
MessageBox.Show($"Customer ID: {customerId}, Address: {customerAddress}")
Else
MessageBox.Show("No data found for Name: " & customerName)
End If
End Using
End Using
End Using
Catch ex As Exception
MessageBox.Show("Error fetching data: " & ex.Message)
End Try
End Sub
Private Sub LoadHtmlContent()
' Define the HTML content
Dim html As String = "<!DOCTYPE html>" &
"<html>" &
"<head>" &
"<title>Test Page</title>" &
"<script type='text/javascript'>" &
"function FetchDataByName() {" &
" if (window.external && typeof window.external.FetchDataByName === 'function') {" &
" var customerName = document.getElementById('inputName').value;" &
" console.log('Fetching data for customer name: ' + customerName);" &
" window.external.FetchDataByName(customerName);" &
" } else {" &
" console.error('window.external.FetchDataByName is not available.');" &
" }" &
"}" &
"</script>" &
"</head>" &
"<body>" &
"<h1>Test Page</h1>" &
"<input type='text' id='inputName' placeholder='Enter Customer Name'>" & ' Changed id to inputName and placeholder text
"<button onclick='FetchDataByName()'>Fetch Data</button>" &
"</body>" &
"</html>"
' Load the HTML content into the WebBrowser control
WebBrowser1.DocumentText = html
End Sub
not fetch data
|
|
|
|
|
AMRO DAMMAM wrote: not fetch data
Did you debug your code?
|
|
|
|
|
You have not given sufficient information to diagnose this. "no fetch data" can mean anything at any point in this code.
You have a bunch of MessageBox statements which should be showing you the important values, but you don't mention anything at all about what they are saying.
|
|
|
|
|
Hi, When I try to install vb6 PRO or visual studio 6 Enterprise on Windows 10 pro 64 bit the following message appears:
access/path error: "cmdInstallvs6_click of frmmain2.frm" and the installation fails here
What does it mean ? How can I solve it ?
Thanks
|
|
|
|
|
You do know VB6 has been dead for over 20 years now, correct?
Even VB.NET isn't being further developed. It gets security and maintenance fixes but is not otherwise being further developed.
|
|
|
|
|
Here is something that (probably) will help you a bit more than some (not necessarily relevant) previous answer
How To Install Visual Basic 6 (VB6) in Windows 10[^]
You may also want to refer to this video, which provides an alternative method for a successful installation on Windows 11.
How to install Visual Basic 6.0 on Windows 11 - YouTube[^]
I have personally installed VB6 on Windows 10 and Windows 11 multiple times on a variety of machines, for a variety of purposes. And while it may not be a straightforward process, it can be done with minimal effort.
Hope this helps.
|
|
|
|
|
i am begginer
i have a Sql database include in 2 tables
i want someone help me to :
- how i connect to database by code
- how i can select tables
- how i read recordes
- what imports needed
thnx
|
|
|
|
|
|
I have to make an application with web service but i never make that.
The web service is Kelio of Bodet.
Somes examples could help me.
Thanks
|
|
|
|
|
Google for "VB.NET webapi client".
There's plenty of examples.
|
|
|
|
|
I want to perform a search in a DataGridView. The search command is working, but I have a problem: a row always remains visible in the DataGridView even if it does not correspond to the search criteria. This row is always the last selected one. I have tried using 'ClearSelection,' and no rows are selected/highlighted, but the problem persists—the same row is still visible. this is my code :
Private Sub TxtboxReserch_TextChanged(sender As Object, e As EventArgs) Handles TxtboxReserch.TextChanged
If TxtboxReserch.Text = "" Then
For i = 0 To DataGridView1.RowCount - 1
DataGridView1.Rows(i).Visible = True
Next
Else
DataGridView1.ClearSelection()
For i = 0 To DataGridView1.RowCount - 1
Try
DataGridView1.Rows(i).Visible = (DataGridView1.Rows(i).Cells(1).Value Like "*" + TxtboxReserch.Text + "*")
Catch ex As Exception
End Try
Next
End If
End Sub
|
|
|
|
|
You already posted this question once; please do not repost.
|
|
|
|
|
I want to perform a search in a DataGridView. The search command is working, but I have a problem: a row always remains visible in the DataGridView even if it does not correspond to the search criteria. This row is always the last selected one. I have tried using 'ClearSelection,' and no rows are selected/highlighted, but the problem persists—the same row is still visible. this is my code :
Private Sub TxtboxReserch_TextChanged(sender As Object, e As EventArgs) Handles TxtboxReserch.TextChanged
If TxtboxReserch.Text = "" Then
For i = 0 To DataGridView1.RowCount - 1
DataGridView1.Rows(i).Visible = True
Next
Else
DataGridView1.ClearSelection()
For i = 0 To DataGridView1.RowCount - 1
Try
DataGridView1.Rows(i).Visible = (DataGridView1.Rows(i).Cells(1).Value Like "*" + TxtboxReserch.Text + "*")
Catch ex As Exception
End Try
Next
End If
End Sub
modified 2-Mar-24 7:25am.
|
|
|
|
|
Try setting the CurrentCell to Nothing .
NB: It would probably be simpler to filter the underlying data source, assuming you have one.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click
Dim i As Integer = DataGridView1.CurrentRow.Index + 1
If i < 0 Then i = 0
DataGridView1.CurrentCell = Me.DataGridView1.Rows(i).Cells(0)
DataGridView1.Rows(i).Selected = True
End Sub
|
|
|
|
|
Look at the error message again. It is telling you that the value of your index variable is outside the range of rows in DataGridView1 . Most likely because of the line below:
Dim i As Integer = DataGridView1.CurrentRow.Index + 1
If you are currently at the last row then "Index + 1" will refer to a row that does not exist.
|
|
|
|
|
|
Check to see whether the value is in range, and not just greater than zero.
|
|
|
|
|
Better user experience:
* Disable the NEXT button when the cursor is on the last row of the grid
* Disable the PREVIOUS button when the cursor is on the first row of the grid
|
|
|
|
|
I want to output a bitmap file to a POS printer using VB6. The ESC/POS mode should be used.
Does the file need to be converted? If yes how? Is there documentation or an example?
Printing and formatting text is no problem. I just can't find any way to solve the problem.
Thank you.
|
|
|
|
|
|
Thank you.
However, the solution does not describe how to use the ESC/POS mode.
|
|
|
|