Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all 27494 articles
Browse latest View live

System.NullReferenceException Error

$
0
0
.
I don't understand the error. Anyone ?

Also, why does VB .NET give correction suggestions for other errors but not this one ? Did I miss a setting during the setup procedure ?

Thank you !


Name:  txtFirstName.jpg
Views: 50
Size:  16.0 KB
Attached Images
 

VS 2005 Make VB remember the username while running.

$
0
0
Hello, its me again, but with a different application - I am making a ChatBot.
So, basically, its quite simple. You say something and it looks for an answer.
And one of the inputs it knows is "my name is ____" and it responds with "Nice to meet you, " + StrLastWord + "!" And it makes it so the last word of the input is the sentence.
s = Split(TextBox1.Text, " ")
strLastWord = s(UBound(s))
This is what makes it identify the last word of a sentence.
Dim Username as String = Nothing
This is what the username is until the user says to the chatbot his name.
So what i want to do is so when someone says, lets say, "My Name Is Duncan", The ChatBot will remember the last word of that input (strlastword) As his name, will know that Username = The last word (duncan), and will remember his name so if it asks it a question, the chat bot will respond "Its blablabla, Duncan." How do i make it remember? Thanks.

VS 2017 Unable to hide a label on a Windows Form

$
0
0
I have a GroupBox on a form. It has four Radio Buttons, that are used to filter a DGV.

The Radio Buttons are No Filter, Type, Constellation and Type. There is an associated ComboBox on the form. If the Constellation Radio Button is selected the ComboBox is populated the Constellation list (extracted from the Constellation column on the DGV). When the No Filter Button is selected, the ComboBox list is cleared. All this works fine.

What I would like to do is, when the No Filter Radio Button is selected I would like to hide the ComboBox and it's associated label.

Hiding the ComboBox is no problem, works fine. Combox Name is "cbFilterValue"

Code:

cbFilterValue.Visible = False
But when I try the same with the label, I get an error. Label Name is "lblFilter"

Code:

lblFilter.Visible = False
I get a lblFilter is not delcared error

What bothers me is that when typing into the editor and I get to "lblFilter.", the Visible property is not displayed.

Please assist.

[RESOLVED] what happened to my app (what is meaning of this page"picture")?

VS 2017 [RESOLVED] Unable to hide a label on a Windows Form

$
0
0
I have a GroupBox on a form. It has four Radio Buttons, that are used to filter a DGV.

The Radio Buttons are No Filter, Type, Constellation and Type. There is an associated ComboBox on the form. If the Constellation Radio Button is selected the ComboBox is populated the Constellation list (extracted from the Constellation column on the DGV). When the No Filter Button is selected, the ComboBox list is cleared. All this works fine.

What I would like to do is, when the No Filter Radio Button is selected I would like to hide the ComboBox and it's associated label.

Hiding the ComboBox is no problem, works fine. Combox Name is "cbFilterValue"

Code:

cbFilterValue.Visible = False
But when I try the same with the label, I get an error. Label Name is "lblFilter"

Code:

lblFilter.Visible = False
I get a lblFilter is not delcared error

What bothers me is that when typing into the editor and I get to "lblFilter.", the Visible property is not displayed.

Please assist.

VS 2010 [RESOLVED] change the Combobox2 drop-down list based on selection from combobox1

$
0
0
I want to change the Combobox2 drop-down list based on selection from combobox1

Code:

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
 me.combobox1.AddRange(New Sting()({"a","b","c"})
 End sub
 
  Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As Object,ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
  if me.combobox1.selectedindex = 0 Then
  me.combobox2.AddRange(New Sting()({"1","2","3"})
  Else me.combobox2.Clear
  exit sub
 end if
 
 if me.combobox1.selectedindex = 1 Then
  me.combobox2.AddRange(New Sting()({"4","5","6"})
  Else me.combobox2.Clear
  exit sub
 end if
 
  if me.combobox1.selectedindex = 2 Then
  me.combobox2.AddRange(New Sting()({"7","8","9"})
  Else me.combobox2.Clear
  exit sub
 end if

Am using the codes above to change the Combobox2 drop-down list based on selection from combobox 1.
Am not successful using those codes


Someone kindly help me
Thank you

Simple way to display/edit custom class properties

$
0
0
I have a custom class. It is built from other custom classes. All the classes have properties that are basic types like integer, double or string. I want a simple way to display and edit the attributes of the class. I will be adding properties to the class as I am developing the app.

I have looked at propertyGrid. It seems to do very well at simple top level properties. When it gets to a property that is a class of simple datatype properties then it just displays the class name grayed out.

I am looking for a simple way to display and edit a custom class in a hierarchy that reflects the underlying class.

Any ideas or pointers to custom controls out there?

Wrtie hexadecimal from another file

$
0
0
Hello,


I've managed to write some hexa in a file to a specific offset

Code:

Dim fs As New IO.FileStream("h:\Bur\2.txt", FileMode.Open, FileAccess.ReadWrite)
        fs.Position = &H350
        fs.WriteByte(&HFF)
        fs.WriteByte(&HFF)
        fs.WriteByte(&HFF)
        fs.WriteByte(&H3F)
        fs.WriteByte(&H0)
        fs.WriteByte(&H1)
        fs.WriteByte(&H0)
        fs.WriteByte(&H0)
        fs.Close()
        fs.Dispose()


I would like to use a file instead of writing each hexadecimal characters.(Taking the hex of a file and writing it in another file to a specific offset)

I have no idea how to do it


If someone could help me

Thanks

Regards

[RESOLVED] Container line

$
0
0
I like to group controls on a form using containers. Typically I use a panel, but sometimes use a combobox. I like to have a fixed line around the container, but I would like to define the color that line should be. I have found nothing in the properties that would allow me to do this. Is there a property that can be defined to set the color of the line, if a fixed line is used?

ListView - Save And Load Items

$
0
0
Hello
i have a two column listview i wanted to know if someone has a method of saving and loading listviews contents! Thanks


im new to vb.net this is a vb6 code i used in my programs to load and save all in one

Code:

'Changed the function return to boolean
' to indicate success or failure.
'Could probably be a Sub since we indicate
' failure with the MsgBox

Public Function SaveLoadListbox(L As ListBox, Contents As String) As Boolean
 Dim LSPath As String
 Dim Txt As String
 Dim i As Long
 Dim fh As Long

 '***note here, App.Path is the folder where
 'your project is saved.  If not saved it will
 'be the path from which VB was launched.  So if
 'you launch VB from the start menu it will be
 'the VB6.exe path.  If you launch VB from a
 'shortcut, it will be the 'StartIn' Path.
 LSPath = App.Path & "\mytext.txt"
 fh = FreeFile  'get an open file handle
 On Error GoTo LSErr  'most common failure would
                      'be the file doesn't exist

 Select Case Contents

  Case "Load"
  Open LSPath For Input As fh
  Do While Not EOF(fh)
    Line Input #fh, Txt 'get the text line at a time
    If Len(Txt) Then    ' & add to the ListBox
    L.AddItem Txt
    End If
  Loop


  Case "Save"
  Open LSPath For Output As fh
  For i = 0 To L.ListCount - 1 'save each line
    Print #fh, L.List(i)        ' of the ListBox
  Next
 End Select

 Close fh
 SaveLoadListbox = True 'success
 Exit Function
LSErr:
 MsgBox "Err: " & Err.Number & " " & Err.Description
End Function


Private Sub Form_Load()
 Debug.Print SaveLoadListbox(List1, "Load")
End Sub

Private Sub Form_Unload(Cancel As Integer)
 Debug.Print SaveLoadListbox(List1, "Save")
End Sub


pic of my listview
Name:  List.png
Views: 51
Size:  7.3 KB
Attached Images
 

VS 2017 .Net Framework 4.6.2 vs .Net Framework 4.7.1

$
0
0
I have a project that I have been working on for a while now. It uses .Net Framework 4.6.2. I was wondering if there is any benefit to upgrade it to .Net Framework 4.7.1.?

I have looked but cannot find a comparison of the two.

Your comments?

VS 2017 Cannot find or open the PDB file

$
0
0
When running my project the Output Window displays the following message:

Quote:

'AstroCompanion.exe' (CLR v4.0.30319: AstroCompanion.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Accessibility\v4.0_4.0.0.0__b03f5f7f11d50a3a\Accessibili ty.dll'. Cannot find or open the PDB file.
It does not seem to affect the running, or functionality, of the code. What am I missing here?

VS 2013 Excel Conditional Formatting in VS2013

$
0
0
Hello,

I'm fighting with the following simple line of code:

Code:

oFormatCondition1 = CType(xlRange.FormatConditions.Add(Type:=Excel.XlFormatConditionType.xlCellValue, Operator:=Excel.XlFormatConditionOperator.xlNotEqual, Formula1:="=RC[-1]"), Excel.FormatCondition)
if I just replace "=RC[-1]" by a numeric value, it's working, but not with this formula!

the condition I want to write is: if this cell value <> the previous cell value (RC[-1])

Can someone help me here ?
Thanks in advance

[RESOLVED] ListView - Save And Load Items

$
0
0
Hello
i have a two column listview i wanted to know if someone has a method of saving and loading listviews contents! Thanks


im new to vb.net this is a vb6 code i used in my programs to load and save all in one

Code:

'Changed the function return to boolean
' to indicate success or failure.
'Could probably be a Sub since we indicate
' failure with the MsgBox

Public Function SaveLoadListbox(L As ListBox, Contents As String) As Boolean
 Dim LSPath As String
 Dim Txt As String
 Dim i As Long
 Dim fh As Long

 '***note here, App.Path is the folder where
 'your project is saved.  If not saved it will
 'be the path from which VB was launched.  So if
 'you launch VB from the start menu it will be
 'the VB6.exe path.  If you launch VB from a
 'shortcut, it will be the 'StartIn' Path.
 LSPath = App.Path & "\mytext.txt"
 fh = FreeFile  'get an open file handle
 On Error GoTo LSErr  'most common failure would
                      'be the file doesn't exist

 Select Case Contents

  Case "Load"
  Open LSPath For Input As fh
  Do While Not EOF(fh)
    Line Input #fh, Txt 'get the text line at a time
    If Len(Txt) Then    ' & add to the ListBox
    L.AddItem Txt
    End If
  Loop


  Case "Save"
  Open LSPath For Output As fh
  For i = 0 To L.ListCount - 1 'save each line
    Print #fh, L.List(i)        ' of the ListBox
  Next
 End Select

 Close fh
 SaveLoadListbox = True 'success
 Exit Function
LSErr:
 MsgBox "Err: " & Err.Number & " " & Err.Description
End Function


Private Sub Form_Load()
 Debug.Print SaveLoadListbox(List1, "Load")
End Sub

Private Sub Form_Unload(Cancel As Integer)
 Debug.Print SaveLoadListbox(List1, "Save")
End Sub


pic of my listview
Name:  List.png
Views: 123
Size:  7.3 KB
Attached Images
 

Listviews - Checkbox Clicked Value

$
0
0
hi
i have a question about a list-views check-boxes i have a list-view with only two columns. I would like to try to change the text of the second column to the check-boxes value of that row that is checked i kinda got it but its not fully working any help would be appreciated thanks

Code:

    Private Sub ListView1_ItemChecked(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemCheckedEventArgs) Handles ListView1.ItemChecked
        Try
            For i As Integer = 0 To ListView1.Items.Count - 1
                ListView1.Items(i).SubItems(1).Text = CStr(Me.ListView1.Items(i).Checked)
            Next
        Catch ex As Exception
            'err
        End Try
    End Sub

here is a pic below
Name:  checkboxes.png
Views: 88
Size:  7.3 KB
Attached Images
 

VS 2017 SaveFileDialog in ConsoleApplication with list?

$
0
0
So i have a multithreaded process in a Do until loop. and i have things i want to write to a text file everytime in that Do until loop. so my thaughts where that i create a list of strings and list.Add() in the Do Until loop. but my problem is that i dont know how to do that. can anybody give me some examples?

VS 2015 How to take values from an unbound datagridview and put them in a sql database table

$
0
0
Good day,

I have a datagrid view and i made it unbound with Datagridview.datasource=nothning
the datagridview is compiled with columns and generated data in columns.
Now i want this data to be saved in a sql database table with the following code:

Code:

For Each row As DataGridViewRow In RestHours2DataGridView.Rows

            Dim conn1 As New SqlConnection

            conn1.ConnectionString = "Data Source=localhost\xxxxxxxxx;Initial Catalog=RestHours;Integrated Security=True"
            conn1.Open()
            Dim cmd1 As New SqlCommand("INSERT INTO RestHours2 (Day) VALUES(@Day)", conn1)

            cmd1.Parameters.AddWithValue("@Day", row.Cells(0).Value)


            cmd1.ExecuteNonQuery()
            conn1.Close()

        Next

now i get the message:
The parameterized query '(@Day nvarchar(4000))INSERT INTO RestHours2 (Day) VALUES(@Day)' expects the parameter '@Day', which was not supplied.

i understand that it now does not take the value from the datagridview
but when i fill the datagridview via the bindingsource then it saves it in the table with the autogenerated columns via this code:

Code:

  If e.RowIndex >= 0 Then
            Me.RestHours2DataGridView.Rows(e.RowIndex).Cells(0).Value = e.RowIndex + 1
         
        End If

How can i make the first code to run that it will save all the data from the DGV ?

Thanks in advance

Best way to create a multiple choice

$
0
0
I am currently just coding in my spare time to try and improve my VB skills (I am new to the language) and I currently have a quiz which generates two random numbers (these numbers are variables from a database) and VB randomized them, it then adds the two numbers and spits out 4 answers and the user does a multi choice and selects the correct ones. My program will also then repeat this process several times and stores each result (answer) in a database and the score of the particular user logged in.

I want to improve the quiz. My quiz is a maths program for children and I wanted to make more questions such as fractions, percentages etc and do them as separate topics within my program but I need a bit of help finding the best way to do so. This is my code so far. I have put it into an Imglur album: https://imgur.com/a/EMQoX

VS 2010 [RESOLVED] Textbox scroll bars won't show

$
0
0
I have a textbox on a form that I am writing text to from within a program. If the textbox starts empty, then I just send the textbox the text I want. If the textbox has anything in it, I add a space then more text.

What I want is HORIZONTAL scroll bars to show up when the textbox is full (horizontally). I have the properties of the textbox set as follows:

TextBox3.AcceptsReturn = True
TextBox3.AcceptsTab = True
TextBox3.MultiLine = True
TextBox3.ScrollBars = Horizontal
TextBox3.WordWrap = True

Here is my code:

Code:

If TextBox3.Text = "" Then
                        TextBox3.Text = Trim(TextBox2.Text)
ElseIf TextBox3.Text <> "" Then
                        TextBox3.Text = TextBox3.Text & " " & Trim(TextBox2.Text)
End If

I cannot get them to appear
HELP!

VS 2012 [RESOLVED] Exiting an If loop

$
0
0
Code:

For b As Integer = 0 To FrontCompared.Count
                        If AlphaNumeric(AlphaDeterminer(FrontCompared(b)), AlphaDeterminer(NextCompared(b))) = 0 Then

                        ElseIf AlphaNumeric(AlphaDeterminer(FrontCompared(b)), AlphaDeterminer(NextCompared(b))) = -1 Then
                            Exit For
                        ElseIf AlphaNumeric(AlphaDeterminer(FrontCompared(b)), AlphaDeterminer(NextCompared(b))) = 1 Then

                        Else
                            Alist.RemoveAt(FcomPosition)
                            Alist.Insert(a + 1, NewWord)
                        End If
                        Exit For
                    Next

the code above compares characters, when the first character(i.e FrontCompared) is equal to the second character(i.e NextCompared), the return must be = 1; and if the first one is less than the second one, the return must be = -1; and if the first one is greater than the second one, the result must be = 1.
So now I want to exit the if loop if the they are equal so that it should go to the next check(i.e b will get to 2 and so on).
Viewing all 27494 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>