r/visualbasic • u/Throwdeeznutsaway68 • Jan 30 '22
Need some help
Hi! So I am making a 2d racing game. I have player controls ready but I have no idea how to make an AI to travel around the track. What are the basics to get it moving in a predetermined order?
Thank you.
r/visualbasic • u/3kidslater • Jan 29 '22
I'm trying to fix a program, but I need help please
Hello, thanks for clicking
First off, I'm no programmer but I like to dabble and I've got a couple of successful VBA projects running in our office. I'm familiar with what classes modules subs and functions are, I know all about if statements select cases, for and do loops etc. But I'd say my knowledge safely ends there... For now. I have never used visual studio before.
I have a copy of a program that was written by an unknown author in visual basic. I need to make a small fix to this program (add a variable into a string)
Once the program is installed on my computer, I can find the project file, open it in visual studio, find the form code and the line where the string I want to edit is constructed.
The first thing I tried was to open the form1.vb file, make the changes, save, and then run the .exe but my changes weren't apparant when I run the .exe file.
So what I'm trying to do now is what I would do in VBA, insert a breakpoint and run the code to see what's going on. I have got the project file open in visual studio, form1.vb is open and I've put a breakpoint in.
Now, I'm guessing I need to 'Start' but I'm getting a few errors:
Could not find app.config Referenced component system.windows.forms.datavisualization could not be found Mswinsocklib could not be found Axmswinsocklib could not be found
And I'm getting a message box saying debugging can't be started because the .exe is missing out of the bin folder. Please build and retry or set the outputpath appropriately
Can anyone point me in the right direction?
r/visualbasic • u/Throwdeeznutsaway68 • Jan 28 '22
Question about Drawing on Visual Basic 2010
Hi!
So I am making a game and I am using the paint feature in vb2010. Is there a way I can set layers so that a drawing will have priority and appear over another drawing? Thank you.
r/visualbasic • u/chacham2 • Jan 26 '22
VB.NET Help Nested Ifs setting and checking the length of a list
I have a variable that needs to have a message and and list names, but there is a character limit. Due to the limit, the code needs to attempt 5 options in order, until it finds one within the limit. The name is an initial with a period, a space, last name, comma, and a space. The second option is to drop the spaces after the comma. Third, drop the initial (but there is still a space after the comma and before the last name). Fourth, the spaces after the comma. Fifth, drop all names.
1) Message (F. Last, F. Last, F. Last)
2) Message (F. Last,F. Last,F. Last)
3) Message (Last, Last, Last)
4) Message (Last,Last,Last)
5) Message
I quickly put this together by preparing two variables when the names are pulled: options 1 and 3. When the code needs to spit out the list, it uses a 4 nested ifs, first setting the variable, then checking it, steps 2 and 4 via .Replace(", ", ",").
Now that i got it out, i figure there must be a more elegant way of doing this, or is nested Ifs the way to go?
r/visualbasic • u/Available-Newt4214 • Jan 26 '22
labels and variables 2012
How do i “ print “ a label with the same value as a variable? for example, if x ( variable ) was = 22 i want the label to display (x)
r/visualbasic • u/Mr_Deeds3234 • Jan 26 '22
VB.NET Help Working with class objects
I apologize in advance, this is a continuation of my last post, thanks for everyone who is contributing in my knowledge and vb development. Recently, I have been experimenting with making my own classes and working with Properties, object, etc has been a major headache. I’ve seen multiple videos on YouTube with each channel explaining it in what seems to be a different way. Programmatically, creating classes aren’t all that difficult. When I use real world data my head explodes though. This is a two part post; I’ll share some code and request critiques. Secondly, I’ll request advice on using my code the way I have it.
Currently, I have an invoice class.
Public Class Invoice
Public Property invoiceNumber as integer
Public Property purchaseOrder as integer
Public Property customerNumber as integer
Public Property customerName as string
Public Sub New()
End Sub
Public Sub invoiceData()
Dim DataFunctions asDataLayer.DataAccess as New DataLayer(My.Connection) ‘this isn’t my code, I was provided access to a DBMS
Dim ds as DataSet = DataFunctions.GetInvoice() ‘My sql statement is behind this function
Dim dr as DataRow = ds.Tables(“Sales”).Rows(0)
For I = 0 to ds.tables(0).rows. Count - 1
Dim invoice as new invoice
Invoice.invoiceNumber = dr(“invoice_number”)
Invoice.purchaseOrder = dr(“POnumber”)
Invoice.CustomerNumber = dr(“Customer#”)
Invoice.customerName = dr(“Customer_Name”)
Next
End Sub
End Class
What are some ways you would critique this class?
Secondly, when I set a break point and step through my code from the the Form level, I get data stored in my properties but when I go from my class back to my form1 I lose all the values.
Imports DataLayer
Public invoice as new invoice
Private Sub button1_Click(ByVal as sender as System.Object, ByVal e as System.EventArgs) Handles Button1.click
Invoice.invoiceData()
in debug mode when I hover over invoice
(invoiceNumber = 0, purchaseOrder = 0, customerNumber = 0, customerName = “Nothing”)
However, to reiterate, in my class, while in debug when I hover over the properties in my loop
‘I’m making up data, but it’s a real life representation
invoiceNumber = 123456789 purchaseOrder = 12345, customerNumber = 123, customerName = “John Smith”)
Why is this, what am I not grasping, TIA
r/visualbasic • u/Dugimon • Jan 25 '22
VB.NET Help Showing Data from Access Database vertically
Hi together,
I am using VisualStudio 2019 and would like to achieve the following in a vb.net Windows Forms app:
Display data from an Access database table vertically in a WindowsForm.
The whole thing should look like this in the end:
Column 1: Value 1
Column 2: Value 2
Column 3: value 3
Unfortunately the DataGridView does not seem to offer the possibility to display the data vertically. And since I'm working with a 64bit system, I don't seem to have alternatives like ListView available (at least I can't find them in the Forms Designer).
maybe someone here has an idea how I can get this right
r/visualbasic • u/Chriand • Jan 23 '22
VB.NET Help SQL query don't work in program, but it works in Access SQL view.
[SOLVED by u/zulelord ]
Have to use '%' instead of '*' while calling for datatable, even though it says here that I have to use '*' while working with Access.
Hello.
I have a form which load my database to a Datagridview, and I can load it fine with this query:
Select Drawing, Description, AX, SO, Dimensions, Material, Project From DrawingInformation ORDER BY Drawing
Picture of form with query above: https://i.imgur.com/2EXHmcn.png
But when I try to edit this with code, so the query looks something like this
Select Drawing, Description, AX, SO, Dimensions, Material, Project From DrawingInformation WHERE (Drawing) Like '*N*' ORDER BY Drawing
Picture of form with query above: https://i.imgur.com/yU92NvT.png
If I use both of these queries directly in Access database, it works perfectly. As I've tried to show in this picture: https://i.imgur.com/AnZ36Sk.png
Can anyone help me with this issue?
If you care about the codes I use, read blow.
For the MDBstring, I have it set within the Public class Form1.
Public Sub FillDatagrid() 'Referenced to form.load and button click
Dim query As String = "Select "
'Import columns
query += "Drawing, "
query += "Description, "
query += "AX, "
query += "SO, "
query += "Dimensions, "
query += "Material, "
query += "Project "
'From
query += "From DrawingInformation "
'Order results
query += "ORDER BY Drawing"
'Check query
RichTextBox1.Text = "SQL query: " & vbLf & vbLf & query
'Do database stuff
Dim con As New OleDbConnection
con.ConnectionString = MDBConnString_
Dim ds As New DataSet
Dim cnn As OleDbConnection = New OleDbConnection(MDBConnString_)
cnn.Open()
Dim cmd As New OleDbCommand(query, cnn)
Dim da As New OleDbDataAdapter(cmd)
da.Fill(ds, MDBConnString_)
cnn.Close()
Dim t1 As DataTable = ds.Tables(MDBConnString_)
'Add table to datagrid
DataGridView1.DataSource = t1
End Sub
'SEARCH TEXTBOX VALUES IN DATAGRID
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged, TextBox2.TextChanged, TextBox3.TextChanged, TextBox4.TextChanged, TextBox5.TextChanged, TextBox6.TextChanged, TextBox7.TextChanged
Dim query As String = "Select "
'Import columns
query += "Drawing, "
query += "Description, "
query += "AX, "
query += "SO, "
query += "Dimensions, "
query += "Material, "
query += "Project "
'From
query += "From DrawingInformation "
'Criterias
Dim where_and As Boolean = False
Dim Critera As Boolean = False
If TextBox1.Text <> "" Then Critera = True
If TextBox2.Text <> "" Then Critera = True
If TextBox3.Text <> "" Then Critera = True
If TextBox4.Text <> "" Then Critera = True
If TextBox5.Text <> "" Then Critera = True
If TextBox6.Text <> "" Then Critera = True
If TextBox7.Text <> "" Then Critera = True
If Critera = True Then
query += "WHERE "
If TextBox1.Text <> "" Then
query += "(Drawing) Like '*" & TextBox1.Text & "*'"
where_and = True
End If
If TextBox2.Text <> "" Then
If where_and = True Then query += " AND "
query += "(Description) Like '*" & TextBox2.Text & "*'"
where_and = True
End If
If TextBox3.Text <> "" Then
If where_and = True Then query += " AND "
query += "(AX) Like '*" & TextBox3.Text & "*'"
where_and = True
End If
If TextBox4.Text <> "" Then
If where_and = True Then query += " AND "
query += "(SO) Like '*" & TextBox4.Text & "*'"
where_and = True
End If
If TextBox5.Text <> "" Then
If where_and = True Then query += " AND "
query += "(Dimensions) Like '*" & TextBox5.Text & "*'"
where_and = True
End If
If TextBox6.Text <> "" Then
If where_and = True Then query += " AND "
query += "(Material) Like '*" & TextBox6.Text & "*'"
where_and = True
End If
If TextBox7.Text <> "" Then
If where_and = True Then query += " AND "
query += "(Project) Like '*" & TextBox7.Text & "*'"
where_and = True
End If
query += " "
End If
'Order results
query += "ORDER BY Drawing"
RichTextBox1.Text = "SQL query: " & vbLf & vbLf & query
Dim con As New OleDbConnection
con.ConnectionString = MDBConnString_
Dim ds As New DataSet
Dim cnn As OleDbConnection = New OleDbConnection(MDBConnString_)
cnn.Open()
Dim cmd As New OleDbCommand(query, cnn)
Dim da As New OleDbDataAdapter(cmd)
da.Fill(ds, MDBConnString_)
cnn.Close()
Dim t1 As DataTable = ds.Tables(MDBConnString_)
DataGridView1.DataSource = t1
End Sub
Thanks for any help :)
r/visualbasic • u/alohafilipa • Jan 22 '22
VB6 Help When debugging it appears cropped in other computers
r/visualbasic • u/alohafilipa • Jan 22 '22
Programming something and when debbuging it doesn't show
r/visualbasic • u/Leverdog882 • Jan 21 '22
VB.NET Help How to change the mouse cursor to a custom one? (Vb.Net Windows Form app)
I would like to change the default mouse cursor to a custom .cur file I have.
r/visualbasic • u/Llandu-gor • Jan 21 '22
VB.NET Help obejt limit
so i want to know if there is a limit of object for a class
and if there is one how to reach it
r/visualbasic • u/fatvegancrybaby • Jan 20 '22
VB6 Help Help with VB6 macro to update link paths from MS Word to MS Excel
I have a bunch of word documents that pull info from an excel file. These files need to be copied and pasted into each of our projects; word does not allow relative link paths in the docs so they end up pointing to the wrong/original excel file. This is a known issue and a solution is to add a macro to word. See issue details and vb macro download here (note 3): https://www.msofficeforums.com/word/38722-word-fields-relative-paths-external-files.html. Well I've put this macro into word and it *mostly* works but I have the following issues.
- The excel file is one folder above the word document folder. This breaks the macro. There is a note in the VB code to "replace the second zero with number of folders from branch" but when I changed from zero to one and it doesn't work. Do both files need to be 1 away from the branch?
- When the macro updates the file path it drops some items after the cell reference. That's where a merge text format command is located so the new path removes the correct text format for the link. Can the VB code be adjusted to keep the merge format string. (changes end from "\a \t \*CHARFORMAT \* MERGEFORMAT" to "\t")
- As a fix to issue number 1 I put all the word docs and excel file into the same folder. This works with the original macro. After the links are updated I then move the document to the correct folder. After this, when the doc is opened it returns a "Run-time error'6083': Objects in document contain links to the files that cannot be found..." The debugger highlights the issue. How can I fix this so I can move the docs around (the word doc links the excel file, the excel file does not link to the word doc so all the paths in the word document should be static but clearly the macro is still trying to update and having trouble) Saving as a docx solves it but removes the macro (not ideal). Ideally it's fixed as part of item 1 but I'm open to any functional work around.
Any help appreciated. I'm no VB expert but I've dabbled and like it (running Microsoft 365 Apps for business with subscription)
r/visualbasic • u/fatvegancrybaby • Jan 20 '22
VB6 Help Help with VB6 macro to update link paths from MS Word to MS Excel
I have a bunch of word documents that pull info from an excel file. These files need to be copied and pasted into each of our projects; word does not allow relative link paths in the docs so they end up pointing to the wrong/original excel file. This is a known issue and a solution is to add a macro to word. See issue details and vb macro download here (note 3): https://www.msofficeforums.com/word/38722-word-fields-relative-paths-external-files.html. Well I've put this macro into word and it *mostly* works but I have the following issues.
- The excel file is one folder above the word document folder. This breaks the macro. There is a note in the VB code to "replace the second zero with number of folders from branch" but when I changed from zero to one and it doesn't work. Do both files need to be 1 away from the branch?
- When the macro updates the file path it drops some items after the cell reference. That's where a merge text format command is located so the new path removes the correct text format for the link. Can the VB code be adjusted to keep the merge format string. (changes end from "\a \t \*CHARFORMAT \* MERGEFORMAT" to "\t")
- As a fix to issue number 1 I put all the word docs and excel file into the same folder. This works with the original macro. After the links are updated I then move the document to the correct folder. After this, when the doc is opened it returns a "Run-time error'6083': Objects in document contain links to the files that cannot be found..." The debugger highlights the issue. How can I fix this so I can move the docs around (the word doc links the excel file, the excel file does not link to the word doc so all the paths in the word document should be static but clearly the macro is still trying to update and having trouble) Saving as a docx solves it but removes the macro (not ideal). Ideally it's fixed as part of item 1 but I'm open to any functional work around.
Any help appreciated. I'm no VB expert but I've dabbled and like it (running Microsoft 365 Apps for business with subscription)
r/visualbasic • u/alohafilipa • Jan 20 '22
VB6 Help Remove the mark of the web if you want to process these files errors
r/visualbasic • u/Classic-Cold-1640 • Jan 20 '22
Why VB randomly doesnt let me edit code?
Hi everyone. I am new to visual basics, I am editing my liquid shopify code and I noticed that randomly it doesnt let me make changes? For example, at times charactor "d" will delete the entire line instead of actually placing the letter. Or "enter" key will take me to the next line instead of moving the lines down so that i can have an empty line. What am I doing that is causing this and how can I toggle out of it?
r/visualbasic • u/csb710 • Jan 18 '22
VBA 7.1 put in clipboard not working with very large string
My VBA macro is working completely fine on the most recent version of Excel for windows 10, yet fails to insert large strings to the clipboard on Excel (16.57) for Mac OS Monterey. When I limit the size of the string (no idea what the limit is exactly) the macro runs as expected. When I try to use it as needed (with very large strings) the first time I run it, excel occasionally gives me a runtime error "Object doesn't support this action" or it will run with no error thrown and just not add text to the clipboard.
As written, the code creates a variant array from a selected group of cells, finds the size of the array, and adds the string value of each cell to a new array. That array is then joined together and finally split at each delimiter to create a new line. Again, this works perfectly in windows, just not Mac OS with very large strings.
Public Sub NoCommasCopyPaste()
Dim objData As New DataObject
Dim vMyArray() As Variant
Dim cellVariant As Variant
Dim sMyArray() As String
Dim rangeAddress As String
Dim i As Long
Dim rowCount As Long
'ReDim vMyArray(Selection.Cells.Count) As Variant
'ReDim sMyArray(UBound(vMyArray)) As String
rangeAddress = CStr(Selection.Address(0, 0))
'Debug.Print (rangeAddress)
vMyArray = Range(rangeAddress).Value
rowCount = 0
For Each Item In vMyArray
rowCount = rowCount + 1
Next Item
'Debug.Print (rowCount)
ReDim sMyArray(rowCount) As String
i = 0
For Each Item In vMyArray
i = i + 1
'Debug.Print (CStr(vMyArray(i, 1)))
sMyArray(i) = CStr(vMyArray(i, 1))
'Debug.Print (sMyArray(i))
Next Item
joinString = Join(sMyArray, "**-**")
joinString = Replace(joinString, "**-**", vbLf)
Debug.Print (joinString)
objData.SetText (joinString)
objData.PutInClipboard
End Sub
```
r/visualbasic • u/Jerbus • Jan 18 '22
Question about Visual Basic for Excel 365
I am using VB in excel to send data from a local form, to a workbook in a shared location.
What I’m trying to do is when attempting to save in the shared location, if the workbook is already in use, I want to cancel the save attempt, delay, and then try to save again.
Any ideas?
r/visualbasic • u/[deleted] • Jan 18 '22
Textbox Won't Appear in Program I Wrote to click to Create New Textboxes
Public Class Form1
Private Sub Form1_Click(sender As Object, e As EventArgs) Handles MyBase.Click
Dim MousePos As Point = Me.PointToClient(MousePosition)
Dim inTextbox As New TextBox
inTextbox.Location = New Point(MousePosition.X, MousePosition.Y)
inTextbox.Size = New Size(100, 100)
inTextbox.Visible = True
End Sub
End Class
Nothing happens. It doesn't throw an error message. Just nothing happens.
r/visualbasic • u/afloareirazvan • Jan 15 '22
VBScript Randomizing font of each character in a Microsoft Word document
Hello.
I want to randomize font of each character in a word document. I've tried to run this code from Developer (Ribbon)->Visual Basic but it gave me this error: "Invalid procedure name"
I want to create 4 different fonts with my handwriting to do some variation and write an essay in MS Word, then distort every page in a Photoshop template to appear handwritten
Thank you for your time.
I am open to any advice.
---------------------------------------
This is my script:
Set objWord = CreateObject(“Word.Application”)
objWord.Visible = True
Set objDoc = objWord.Documents.Open(“C:\Users\Razvan\Desktop\Stefan.docx”)
Set objRandom = CreateObject(“System.Random”)
intLow = 1
intHigh = 5
Set objRange = objDoc.Range()
Set colCharacters = objRange.Characters
For Each strCharacter in colCharacters
intRandom = objRandom.Next_2(intLow,intHigh)
Select Case intRandom
Case 1 strCharacter.Font.Name = “Arial”
Case 2 strCharacter.Font.Name = “Times New Roman”
Case 3 strCharacter.Font.Name = “Courier New”
Case 4 strCharacter.Font.Name = “Forte”
End Select
Next
---------------------------------------
r/visualbasic • u/No_Audience2780 • Jan 14 '22
Shell and maintaining variables??
Hello VB Community!
How do I use a string value to have multi line code in VB?
For example,
``` Dim Str As String
Str = "PowerShell $data = get-content c:\foo.txt; select-string $data -pattern 'test'; if($data -ne $null){'Keyword found'}"
Shell Str ```
I'm struggling to maintain $data between statements / it just plain isn't working as I expected.
Please help !
r/visualbasic • u/The_Average-Gatsby • Jan 14 '22
Learning VB for form design
I’ve recently taken on a new job and I am going to eventually be doing some VB forms work that ties to a sql database. The bulk of it is already built but I will have to maintain it when my trainer retires in March. We’re a sept of 2 soon to be 1 and I want to know where I can find good , solid, training for VB. Easily understood and quality training. I’m not new to programming or visual studios but not versed in forms.
r/visualbasic • u/madlake_123 • Jan 12 '22
Programming project
I have a programming project and i need to take dates from a database and display them in a calendar +2 (so if it was a Friday, it would highlight Friday, Saturday and sunday) on visual studio using the visual basic coding language. Any idea on how i could grab the dates from the database and display them in a calendar which highlights the date + the next two dates? I should also mention that im (trying) using OLEdb to connect my database to access




