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

Please Help!! Im on a deadline and I cant figure this out!!

$
0
0
I have Visual Studio 2017. These are the directions I was given:

Using what you know about search arrays, implement the VerifyUsername and VerifyPassword functions. They should return true if the username or password is found in the arrUsernames or arrPasswords array, respectively.

You should get an error message using the blnLoggedIn variable. In the next lesson, you’ll be introduced to access modifiers, but for right now, just know that you need to change the Dim keyword to Friend. See what happens when you type in an incorrect username and password.

I already changed the Dim keyword to Friend. I have also done several Elseif and if statements and I still get the same error saying im missing my return statements. Im not sure if Im writing it wrong?? Can someone PLEASE HELP!!!?? I wasnt able to upload my proj but I can post it here as a Google drive link

https://drive.google.com/file/d/1_og...ew?usp=sharing

You will have to open with Visual Studio..the link has it in document form

VS 2017 Please your help to solve "olMailItem is not declared. It may be inaccessible due to

$
0
0
Hello All,

Since I have just started to learn Visual Basic via the Visual Studio 2017 Community version, where I also wanted to learn to create Mail items in Outlook via VB commonds.

Via an online VB article I got following example to create mail item in outlook via VB, but somehow I still got the enclosed Error message which I still have not managed to resolve after several hours of debugging efforts.
The Error message related to the code line "myMessage = _App...." is as follows:
"olMailItem is not declared. It may be inaccessible due to its protection level"
Please your help and suggestions how I can resolve this issue.
Many thanks in advance, and cheers!
Son

--------------------------------------------------------------
'Create e-mail item

Dim myMessage As Object
myMessage = _Application.CreateItem(ItemType:=olMailItem)
With myMessage
.To = "test@ example.com"
.Subject = "Test message"
.Body = "This is a test message."
.Display()
End With
Attached Images
 

Array or List

$
0
0
So for those of you who do not know, I created a Visual Basic FAQ thread on which collection should I use. However, I ran across a situation that I need y'all's help on figuring out which collection I should use.

My situation is this: I have a bunch of sensors that I monitor, I click a Button and it scans for all of the sensors. When the scan is finished it returns a fixed collection of sensors, which I store into an array. However, with this being a possibility of being rescanned, I feel like I should use a List instead since the number of items can change. So my question to y'all, is which should I use:

Fixed collection solution:
Code:

'Declared at the Form level: Dim sensors() As Sensor

'Redeclare the variable to match the number of returned sensors
ReDim sensors(monitor.Sensors.Count - 1)

'Create a counter to keep track of where to insert the sensor in the array
Dim counter As Integer = 0

'Iterate through each sensor
For Each sensor As HostSensor In monitor.Hosts
    'Add the sensor to the array
    sensors(counter) = New Sensor() With {.IP = sensor.IPAddressString, .Name = sensor.Name}

    'Increment the counter
    counter += 1
Next

Dynamic length collection:
Code:

'Declared at the Form level: Dim sensors As New List(Of Sensor)

'Clear the collection
sensors.Clear()

'Iterate through each sensor
For Each sensor As HostSensor In monitor.Hosts
    'Add the sensor to the array
    sensors.Add(New Sensor() With {.IP = sensor.IPAddressString, .Name = sensor.Name})
Next

Anyway to force Excel RefreshAll to ask for credentials via code?

$
0
0
I am working on a project where I am refactoring code to be asynchronous. I am using Async/Await using Task.Run and in my code block I call the excel worksheets "RefreshAll". When called it prompts for the credentials for the server connection with which it will refresh from. Since I set this up using Async, it now prompts for the credentials but does not wait for them to be entered before continuing and will continue running the rest of the code which causes a number of errors because the credentials have not been entered yet. So I was thinking that if I can force the credentials to be entered before I make my async/await call, it would solve my issue. However I can't seem to find a way to do this. I'm open to any other ideas if anyone has any.

Thanks!

Code:

Private Async Function RefreshReport_OrigBakgroundWorker1(xlsWorkbook As Excel.Workbook, conn As SqlConnection, Optional autoId As Integer = -1) As Task
        Try
            xlsWorkbook.RefreshAll() '<-- This is where it prompts for the credentials and I would like to force it to ask in another code block
            Log("Refresh done and call save for report: " & xlsWorkbook.Name)
            xlsWorkbook.Save()
            Log("Save done for report: " & xlsWorkbook.Name)
        Catch ex As Exception
            Log("Error in RefreshReport_OrigBakgroundWorker1: " + ex.Message, LogType.LogError)
        Finally

        End Try

    End Function

Event for Detecting Failed Drag/Drop

$
0
0
In my application code is executed during drag/drop which draws pretty cool looking x's across controls that won't accept a drop. Everything works fine if the drag/drop is succesful because i erase the x's in the dragdrop event, but if the user lets go of the left mouse button over a control which doesn't accept a drop then the x's stay on the screen I need an event which is triggered if the drag drop fails. I tried using a simple mouseup event for the entire form but it hasn't worked for some reason.

Any help would be appreciated. Thanx!

[RESOLVED] Background color

$
0
0
Below is a form with a DGV. As can be seen, the background color for the column headers is white. I do not want them to be white. It is obvious to me that "
.ColumnHeadersDefaultCellStyle.BackColor = Color.Wheat"
is not correct. I have attempted numerous other approaches with no better results. So exactly what can I do to get the background color of the header columns to be what I want them to be.


Code:

        With dgvSignList
            .Enabled = False
            .BackgroundColor = Color.Tan
            .EnableHeadersVisualStyles = True
            .ColumnHeadersVisible = True
            .BorderStyle = BorderStyle.None
            'Headers
            .ColumnHeadersDefaultCellStyle.Font = New Font("Times New Roman", 11, FontStyle.Bold)
            .ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
            .ColumnHeadersDefaultCellStyle.BackColor = Color.Wheat
            'Cells
            .DefaultCellStyle.Font = New Font("Times New Roman", 11, FontStyle.Regular)
            .DefaultCellStyle.ForeColor = Color.Black
            .DefaultCellStyle.BackColor = Color.AntiqueWhite
            .DefaultCellStyle.SelectionBackColor = Color.AntiqueWhite
            .DefaultCellStyle.SelectionForeColor = Color.Black
            .DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft
        End With

Name:  SignList.jpg
Views: 65
Size:  19.9 KB
Attached Images
 

Animatronic seqeuncing?

$
0
0
Hello everyone! As you can probably tell by my username, I generally work with animatronics and their control systems, as a hobby. Right now, I am developing a software that interfaces with a serial device which interprets serial messages into animatronic movements. Essentially, what happens is the home-row keys on the keyboard (a s d f j k l ;) can each be mapped to one of many serial signals on the serial device. At the same time, a VLC media player plugin plays an audio file. There is also a timer that starts at the same time as the audio in order to keep time. When each keyboard button is pressed, the current elapsed milliseconds are recorded in a list box, and upon release, the same thing occurs in a separate list box. This is where I am running into issues; I cannot playback the sequences. I am unsure how to get the code to constantly compare the current elapsed milliseconds with the currently selected list box item. Does anyone have a suggestion on how I can achieve this? Note: the sequence playback needs to occur both during "playback mode" and "record mode" in order the visualize the full sequence that is being done, since sequencing is usually done is several passes. If list boxes aren't the way to go, that would be ok. They were just my initial idea. Note that the sequences eventually need to be saved and opened somehow. By the way, I am using VB 2010 Express.

Thanks for reading.

VS 2017 What does no value given for one or more required parameters mean? How to fix?

$
0
0
all I'm making a program in which the user can update a table of their choice from a list box. When an item in the list box is selected, it shows the MS-Access database in the DataGridView. When a user selects a cell in the DataGridView, it will show the ID, the field name and the actual data inside the selected cell in textboxes, so the user can change the table. Once they click btnUpdateTable an UPDATE query will be run to change the cell data based on the ID and the field name.

However, when clicking btnUpdateTable a message box appears reading:

"No value is given for one or more required parameters"

I don't know what the problem is and how to fix it, I don't understand what parameter is null. Thanks all, appreciate it. Below is the code:

Code:

Imports System.Data.OleDb
Public Class frmViewTables
    Dim connString As String = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & Application.StartupPath & "\SAC1 Database.mdb"
    Dim MyConn As New OleDbConnection
    Dim da As OleDbDataAdapter
    Dim ds As DataSet
    Dim tables As DataTableCollection
    Dim source1 As New BindingSource
    Dim dt As DataTable
    Dim SelectedTable As String

    Private Sub lbxTables_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lbxTables.SelectedIndexChanged

        If lbxTables.SelectedItem = "tblOrders" And frmLogin.AdminDetails = True Then
            SelectedTable = "tblOrders"
            Dim source1 As New BindingSource
            Dim ds = New DataSet
            Dim tables = ds.Tables
            Dim cn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & Application.StartupPath & "\SAC1 Database.mdb")
            Dim da As OleDbDataAdapter = New OleDbDataAdapter()
            Dim cmd As New OleDbCommand("Select * from [tblOrders]", cn)
            da.SelectCommand = cmd
            da.Fill(ds, "tblOrders")
            Dim view As New DataView(tables(0))
            source1.DataSource = view
            dgvDynamic.DataSource = view
        ElseIf lbxTables.SelectedItem = "tblOrders" Then
            SelectedTable = "tblOrders"
            Dim source1 As New BindingSource
            Dim ds = New DataSet
            Dim tables = ds.Tables
            Dim cn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & Application.StartupPath & "\SAC1 Database.mdb")
            Dim da As OleDbDataAdapter = New OleDbDataAdapter()
            Dim cmd As New OleDbCommand("Select * from [tblOrders] where Username = @username", cn)
            cmd.Parameters.Add("@username", OleDbType.VarChar, 255).Value = frmLogin.SuccessfulLoginUsername
            da.SelectCommand = cmd
            da.Fill(ds, "tblOrders")
            Dim view As New DataView(tables(0))
            source1.DataSource = view
            dgvDynamic.DataSource = view
        End If

        If lbxTables.SelectedItem = "tblTickets" And frmLogin.AdminDetails = True Then
            SelectedTable = "tblTickets"
            Dim source1 As New BindingSource
            Dim ds = New DataSet
            Dim tables = ds.Tables
            Dim cn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & Application.StartupPath & "\SAC1 Database.mdb")
            Dim da As OleDbDataAdapter = New OleDbDataAdapter()
            Dim cmd As New OleDbCommand("Select * from [tblTickets]", cn)
            da.SelectCommand = cmd
            da.Fill(ds, "tblTickets")
            Dim view As New DataView(tables(0))
            source1.DataSource = view
            dgvDynamic.DataSource = view
        ElseIf lbxTables.SelectedItem = "tblTickets" Then
            SelectedTable = "tblTickets"
            Dim source1 As New BindingSource
            Dim ds = New DataSet
            Dim tables = ds.Tables
            Dim cn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & Application.StartupPath & "\SAC1 Database.mdb")
            Dim da As OleDbDataAdapter = New OleDbDataAdapter()
            Dim cmd As New OleDbCommand("Select * from [tblTickets] where Username = @username", cn)
            cmd.Parameters.Add("@username", OleDbType.VarChar, 255).Value = frmLogin.SuccessfulLoginUsername
            da.SelectCommand = cmd
            da.Fill(ds, "tblTickets")
            Dim view As New DataView(tables(0))
            source1.DataSource = view
            dgvDynamic.DataSource = view
        End If

        If lbxTables.SelectedItem = "tblUsers" And frmLogin.AdminDetails = True Then
            SelectedTable = "tblUsers"
            Dim source1 As New BindingSource
            Dim ds = New DataSet
            Dim tables = ds.Tables
            Dim cn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & Application.StartupPath & "\SAC1 Database.mdb")
            Dim da As OleDbDataAdapter = New OleDbDataAdapter()
            Dim cmd As New OleDbCommand("Select * from [tblUsers]", cn)
            da.SelectCommand = cmd
            da.Fill(ds, "tblTickets")
            Dim view As New DataView(tables(0))
            source1.DataSource = view
            dgvDynamic.DataSource = view
        End If
    End Sub

    Private Sub frmViewTables_Shown(sender As Object, e As EventArgs) Handles Me.Shown

        If frmLogin.AdminDetails = True Then
            lbxTables.Items.Add("tblUsers")
            lbxTables.Items.Add("tblOrders")
            lbxTables.Items.Add("tblTickets")
            dgvDynamic.ReadOnly = False
        Else
            lbxTables.Items.Add("tblOrders")
            lbxTables.Items.Add("tblTickets")
        End If

    End Sub

    Private Sub dgvDynamic_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgvDynamic.CellClick

        txtID.Text = dgvDynamic.CurrentRow.Cells(0).Value.ToString()
        txtSelectedCellData.Text = dgvDynamic.CurrentCell.Value.ToString()
        For Each c As DataGridViewCell In dgvDynamic.SelectedCells
            txtColumnName.Text = (dgvDynamic.Columns(c.ColumnIndex).HeaderText)
        Next

    End Sub

    Private Sub GetRecordID()
        Dim rowContent As String = String.Empty

        dgvDynamic.CurrentRow.Cells(0).Value.ToString()
        MessageBox.Show(dgvDynamic.CurrentRow.Cells(0).Value.ToString())

    End Sub

    Private Sub btnGetID_Click(sender As Object, e As EventArgs) Handles btnGetID.Click
        GetRecordID()
    End Sub

    Private Sub GetColumnName()
        For Each c As DataGridViewCell In dgvDynamic.SelectedCells
            MessageBox.Show(dgvDynamic.Columns(c.ColumnIndex).HeaderText)
        Next
    End Sub

    Private Sub btnGetColumnName_Click(sender As Object, e As EventArgs) Handles btnGetColumnName.Click
        GetColumnName()
    End Sub

    Private Sub btnUpdateTable_Click(sender As Object, e As EventArgs) Handles btnUpdateTable.Click
        Dim tblName As String = SelectedTable
        Dim colName As String = txtColumnName.Text
        Dim recID As String = txtID.Text
        Dim NewData As String = txtSelectedCellData.Text

        Try
            Dim con As New OleDbConnection(connString)
            con.Open()
            Dim cmd As New OleDbCommand("UPDATE [" & tblName & "] SET [" & colName & "] = @NewData WHERE ID = @recID", con)
            cmd.ExecuteNonQuery()

            cm.Parameters.Add(New OleDbParameter("@NewData", OleDbType.VarChar, 255, NewData))
            cm.Parameters.Add(New OleDbParameter("@recID", OleDbType.VarChar, 255, recID))


            cm.Parameters("@NewData").Value = NewData
            cm.Parameters("@recID").Value = recID



        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical)
        End Try

    End Sub

End Class

VS 2015 [RESOLVED] dgv colums filled with data from unbound textboxes does not save in sql table

$
0
0
Good day,

I have a datagridview with 2 colums that get filled from 2 textboxes, when i hit the button it puts it in the datagridview and when i save it, it does not saves it in the sql table.
when i fill the cells manually it saves the data.
The datagridview is databound
i fill the colums with this line of code:
Code:

RestHours2DataGridView.Columns("Month1").DefaultCellStyle.NullValue = TextBox2.Text
        RestHours2DataGridView.Columns("Year1").DefaultCellStyle.NullValue = TextBox3.Text

Thanks for the help

VS 2010 dumb question

$
0
0
In general are link statements slower than writing your own code? I will be running for millions of times.
Thank you
George

VS 2010 CAn't open forms from a VS2010 project which I converted from a VB2008 project

$
0
0
I just converted a VS2008 project to a VS2010 project (I know , it's still old ! ) and although I got the message that the conversion was completed successfully , when I double click any form in the solution Explorer , I get this message :


How can this be ? ? ? that the VS2010 cannot open forms ?
Also , I looked in the Error List to see what was going on , but I couldn't understand a thing ...

VS 2015 [RESOLVED] Counting the colums with value and put them in sql datatable

$
0
0
Good day,

I have a datagridview and i want to count the columns in each row with the value true and that that value be saved in a sql database table and displayed in the hours rest column for each row

Name:  Knipsel.jpg
Views: 72
Size:  8.7 KB

The colums painted green are the values true.
i have a query to count all the true columns and calculate them, but i do not know how to implement this in my save button code, see below my query

Code:

SELECT t.ID,
SUM(CASE WHEN n = 1 THEN 1.0 ELSE 0.0 END)/2 AS RestHours
FROM RestHours2 t
CROSS APPLY (VALUES
([1]),([2]),([3]),([4]),([5]),([6]),([7]),([8]),([9]),([10]),([11]),([12]),([13]),([14]),([15]),([16]),
([17]),([18]),([19]),([20]),([21]),([22]),([23]),([24]),([25]),([26]),([27]),([28]),([29]),([30]),([31]),([32]),
([33]),([34]),([35]),([36]),([37]),([38]),([39]),([40]),([41]),([42]),([43]),([44]),([45]),([46]),([47]),([48]))m(n)
GROUP By ID

Attached Images
 

Problems creating and formatting excel chart

$
0
0
I'm going to try to be specific about this question but everything I'm doing to try to create and excel chart through vb seems to be going wrong.

Here's my code with questions inserted. xlSheetEffectivity is defined as an excel sheet further up the code. locationList is a list defined elsewhere. This is within a with block that uses an excel sheet.

Dim innerChordChartPage As Excel.Chart
Dim innerChordCharts As Excel.ChartObjects
Dim innerChordChart As Excel.ChartObject
Dim sourceRange = .Range(.Cells(15, 6), .Cells(15 + (locationList.Count * 3 - 4), 6))
Dim xRange = .Range(.Cells(15, 5), .Cells(15 + (locationList.Count * 3 - 4), 5))
Dim yRangeICMax = .Range(.Cells(15, 6), .Cells(15 + (locationList.Count * 3 - 4), 6))
Dim yRangeICMin = .Range(.Cells(15, 7), .Cells(15 + (locationList.Count * 3 - 4), 7))


innerChordCharts = .ChartObjects
innerChordChart = innerChordCharts.Add(180, 80, 300, 250)
innerChordChartPage = innerChordChart.Chart

With innerChordChartPage
.SetSourceData(Source:=sourceRange)))
.ChartType = Excel.XlChartType.xlXYScatterLines
.SeriesCollection(1).name = "Maximum" <------Everything seems ok to here
.SeriesCollection(1).xValues = xRange <------This gives me an error saying something about a missing member
.SeriesCollection(1).Values = yRangeICMax <------This gives me an error saying something about a missing member
.SeriesCollection.NewSeries()
.SeriesCollection(2).name = "Minimum"
.SeriesCollection(2).xValues = xRange <------This gives me an error saying something about a missing member
.SeriesCollection(2).Values = yRangeICMin <------This gives me an error saying something about a missing member
.Axes(Excel.XlCategoryType.xlAutomaticScale).MinimumScale = xlSheetEffectivity.Cells(15, 5).Value - 2 <--------Error says: The specified dimension is not valid for the current chart type

------------>I haven't gotten past this point<-----------------

.Axes(Excel.XlCategoryType.xlAutomaticScale).MaximumScale = xlSheetEffectivity.Cells(15 + locationList.Count, 5).Value + 2
.Axes(Excel.XlCategoryType.xlAutomaticScale).MajorUnit = 20
.ApplyLayout(1)
.ChartTitle.Text = "Inner Chord Stress"
.Axes(Excel.XlAxisGroup.xlPrimary).AxisTitle.Text = "Stress (KSI)"
.Axes(Excel.XlAxisGroup.xlSecondary).AxisTitle.Text = "Body Station"
.LeftColumn = 9
.TopRow = ICTableStartRow
.Width = 913.68
.Height = 529.2
End With

I tried changing the ranges to a letter format: xlSheetEffectivity.Range("E15:F20") and also: xlSheetEffectivity.Range("E15","F20"). This still didn't work. I can turn these into strings in the same way the macro makes them but this is less than ideal since the ranges aren't always the same. I don't understand why the chart won't accept a range like everything else in excel. I haven't tried much else with the .axes lines. I've tried looking up these problems but can't seem to find a solution that works. Any help is appreciated.

Help needed for error "failed to convert parameter value from sting to Datetime"

$
0
0
Hi Senior Colleagues,
I am trying to insert data from datagridview into database but after running the program i received this error message:
"Failed to convert parameter from string to datetime".

Below is the written code. I wish people mentor me through to the end.
Thanks in advance.

Here is my code.....

vb.net Code:
  1. Dim dgvconnection As New SqlConnection("Data Source=(LocalDB)\v11.0;AttachDbFilename=D:\Visual Basic Project\Church Database System\WindowsApplication1\cms.mdf;Integrated Security=True")
  2.         Dim dgvcommand As SqlCommand = dgvconnection.CreateCommand()
  3.  
  4.  
  5.         Try
  6.             'open connection
  7.             dgvconnection.Open()
  8.  
  9.             'create Insert statement with named parameters
  10.             dgvcommand.CommandText = "Insert into members(id,datemembregis,year,Title,FullName,MaidName,DOB,Age,Gender,HomeTown,POB,MemStatus,MemType,MaritalStatus,MarriageType,SpouseName,SpouseDeno,DOBap,PlaceofBap,DOConf,PlaceofConf,gengroup,sergroup,othergroup,daygroup,memsince,transfer) values(@id,@datemembregis,@year,@title,@fullname,@maidname,@dob,@Age,@gender,@hometown,@pob,@MemStatus,@MemType,@maritalstatus,@marriagetype,@SpouseName,@SpouseDeno,@dobap,@placeofbap,@doconf,@placeofconf,@gengroup,@sergroup,@othergroup,@daygroup,@memsince,@transfer)"
  11.  
  12.             'add parameters to command parameters collection
  13.             dgvcommand.Parameters.Add("@id", SqlDbType.Int, 50)
  14.             dgvcommand.Parameters.Add("@datemembregis", SqlDbType.SmallDateTime)
  15.             dgvcommand.Parameters.Add("@year", SqlDbType.NChar, 10)
  16.             dgvcommand.Parameters.Add("@title", SqlDbType.NChar, 10)
  17.             dgvcommand.Parameters.Add("@fullname", SqlDbType.VarChar, 50)
  18.             dgvcommand.Parameters.Add("@maidname", SqlDbType.VarChar, 50)
  19.             dgvcommand.Parameters.Add("@dob", SqlDbType.SmallDateTime)
  20.             dgvcommand.Parameters.Add("@age", SqlDbType.VarChar, 50)
  21.             dgvcommand.Parameters.Add("@gender", SqlDbType.VarChar, 50)
  22.             dgvcommand.Parameters.Add("@hometown", SqlDbType.VarChar, 50)
  23.             dgvcommand.Parameters.Add("@pob", SqlDbType.VarChar, 50)
  24.             dgvcommand.Parameters.Add("@memstatus", SqlDbType.VarChar, 50)
  25.  
  26.             dgvcommand.Parameters.Add("@memtype", SqlDbType.VarChar, 50)
  27.             dgvcommand.Parameters.Add("@maritalstatus", SqlDbType.VarChar, 50)
  28.             dgvcommand.Parameters.Add("@marriagetype", SqlDbType.VarChar, 50)
  29.             dgvcommand.Parameters.Add("@spousename", SqlDbType.VarChar, 50)
  30.             dgvcommand.Parameters.Add("@spousedeno", SqlDbType.VarChar, 50)
  31.             dgvcommand.Parameters.Add("@dobap", SqlDbType.SmallDateTime)
  32.             dgvcommand.Parameters.Add("@placeofbap", SqlDbType.VarChar, 50)
  33.             dgvcommand.Parameters.Add("@doconf", SqlDbType.SmallDateTime)
  34.             dgvcommand.Parameters.Add("@placeofconf", SqlDbType.VarChar, 50)
  35.             dgvcommand.Parameters.Add("@gengroup", SqlDbType.VarChar, 50)
  36.             dgvcommand.Parameters.Add("@sergroup", SqlDbType.VarChar, 50)
  37.             dgvcommand.Parameters.Add("@othergroup", SqlDbType.VarChar, 50)
  38.             dgvcommand.Parameters.Add("@daygroup", SqlDbType.VarChar, 50)
  39.             dgvcommand.Parameters.Add("@memsince", SqlDbType.VarChar, 50)
  40.             dgvcommand.Parameters.Add("@transfer", SqlDbType.VarChar, 50)
  41.  
  42.             'prepare command for repeated execution
  43.             dgvcommand.Prepare()
  44.  
  45.             'data to be inserted
  46.             For Each row As DataGridViewRow In dgvExcelRegistration.Rows
  47.                 If Not row.IsNewRow Then
  48.  
  49.                     dgvcommand.Parameters("@id").Value = row.Cells("id").Value
  50.                     dgvcommand.Parameters("@datemembregis").SqlValue = row.Cells("DateReg").Value
  51.                     dgvcommand.Parameters("@year").Value = row.Cells("year").Value
  52.                     dgvcommand.Parameters("@title").Value = row.Cells("Title").Value
  53.                     dgvcommand.Parameters("@fullname").Value = row.Cells("FullName").Value
  54.                     dgvcommand.Parameters("@maidname").Value = row.Cells("Maiden").Value
  55.                     dgvcommand.Parameters("@dob").SqlValue = row.Cells("DOB").Value
  56.                     dgvcommand.Parameters("@age").Value = row.Cells("Age").Value
  57.                     dgvcommand.Parameters("@gender").Value = row.Cells("Gender").Value
  58.                     dgvcommand.Parameters("@hometown").Value = row.Cells("HomeTown").Value
  59.                     dgvcommand.Parameters("@pob").Value = row.Cells("POB").Value
  60.                     dgvcommand.Parameters("@memstatus").Value = row.Cells("MemStatus").Value
  61.  
  62.                     dgvcommand.Parameters("@memtype").Value = row.Cells("MemType").Value
  63.                     dgvcommand.Parameters("@maritalstatus").Value = row.Cells("MaritalStatus").Value
  64.                     dgvcommand.Parameters("@marriagetype").Value = row.Cells("MaritalType").Value
  65.                     dgvcommand.Parameters("@spousename").Value = row.Cells("SpouseName").Value
  66.                     dgvcommand.Parameters("@spousedeno").Value = row.Cells("SpouseDeno").Value
  67.                     dgvcommand.Parameters("@dobap").SqlValue = row.Cells("DOBapt").Value
  68.                     dgvcommand.Parameters("@placeofbap").Value = row.Cells("PlaceBaptism").Value
  69.                     dgvcommand.Parameters("@doconf").SqlValue = row.Cells("ConfDate").Value
  70.                     dgvcommand.Parameters("@placeofconf").Value = row.Cells("ConfPlace").Value
  71.                     dgvcommand.Parameters("@gengroup").Value = row.Cells("GenGroup").Value
  72.                     dgvcommand.Parameters("@sergroup").Value = row.Cells("ServiceGrp").Value
  73.                     dgvcommand.Parameters("@othergroup").Value = row.Cells("OtherGrp").Value
  74.                     dgvcommand.Parameters("@daygroup").Value = row.Cells("DayBorn").Value
  75.                     dgvcommand.Parameters("@memsince").Value = row.Cells("MemSince").Value
  76.                     dgvcommand.Parameters("@transfer").Value = row.Cells("TransferFrom").Value
  77.  
  78.                     dgvcommand.ExecuteNonQuery()
  79.                     dgvcommand.Parameters.Clear()
  80.                 End If
  81.             Next
  82.  
  83.         Catch ex As Exception
  84.             MessageBox.Show(ex.Message)
  85.  
  86.         Finally
  87.             dgvconnection.Close()
  88.         End Try

VS 2017 Looking for ideas for my exam project within or above my skill level.

$
0
0
Hello i have recently successfully finished my first real program which works but could be better. And now i am looking for a new challenge which i could use as an exam project.

I think it's fair to say that i am a novice in VB.net, i don't have any books i use mostly the internet to get the answer i seek mostly by doing research and doing tutorials and guides.
Here are two ideas that i thought about;

  • Inventory Management Simulator with databases (Access)
  • Download Manager

I think both of them sound challenging and yet being something that i should be able to make.

If you would like to see my first program which is a soda machine program, here is a mega link to it https://mega.nz/#!YtgEiabZ!xrU-LE-eL...fVrshi2pk9ecmw Contains source code with explanations and a release build in the bin folder!
Here is the source code and picture of the program if you don't wish to download it:
Code:

https://pastebin.com/gmshM8jH
Too long for this thread

Name:  36a35234d519dd66568f5e109814ec75.jpg
Views: 54
Size:  46.8 KB

If anyone is just interested in my program and would like to take a look you're welcome, but i do appreciate any feedback i can get!
I am also looking for any good material or any good help sheet or cheat sheet of some kind, basically any good resource of some kind that could help me greatly.
Thanks in advance for any feedback or ideas for a program.
Attached Images
 

[RESOLVED] Unresolved Errors in VB.Net Code

$
0
0
.
Here is my first coding issue starting with VB .NET.

The errors in the below code are indicated with the LESS THAN symbol. <<<<<<<<<<<<<<<<<<<<<<<<
I've tried editing the code per the built-in suggestions without success. This code is from an online training course at : http://www.homeandlearn.co.uk/NET/nets12p6.html

Code:

Public Class Form1
    Private Sub TblContactsBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) Handles TblContactsBindingNavigatorSaveItem.Click
        Me.Validate()
        Me.TblContactsBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.AddressBookDataSet)

    End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'AddressBookDataSet.tblContacts' table. You can move, or remove it, as needed.
        Me.TblContactsTableAdapter.Fill(Me.AddressBookDataSet.tblContacts)

    End Sub

    Private Sub BtnLoad_Click(Sender As Object, e As EventArgs) Handles btnLoad.Click
        'Above line underscored as error. 'End Sub expected'  There is an End Sub at bottom ... ???  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
   
    Dim con As New OleDb.OleDbConnection    'The Connection Object

    Dim dbProvider As String        'Holds the provider
    Dim dbSource As String          'Holds the Data Source
    Dim MyDocumentsFolder As String    'Holds the Documents Folder
    Dim TheDatabase As String      'Holds the Database Name       
    Dim FullDatabasePath As String      'Holds the Database Path
    Dim ds as new Dataset          'Holds a Dataset Object
    Dim da as OleDb.OleDbDataAdapter    'Holds a SQL String

        'Set up the Provider
        dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"

        'Set the databse and where the database is
        TheDatabase = "/AddressBook.mdb"
        MyDocumentsFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
        FullDatabasePath = MyDocumentsFolder & TheDatabase

        'Set the datasource
        dbSource = "Data Source = " & FullDatabasePath

        'Set the connection string
        con.ConnectionString = dbProvider & dbSource

        'Open the database
        con.Open()

        'Store the SQL string
      sql= "Select * FROM tblContacts
        'sql above underscored as error. 'System.Data.Sql is a namespace and cannot be used as an expression'  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

            'Pass the SQL string and connection object to the Data_Adapter
            da = New OleDb.OleDbDataAdapter(sql, con)
     
        'Open the Database
        con.Open()
        MessageBox.Show("DB Open")

        'Close the Database
        con.Close()
        MessageBox.Show("DB Closed")                                                                        '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                        'The last quotation mark and ) are underscored. 'String constants must end with double quotes' That resolution does not work.
       
End Sub                'End Sub and End Class underscored. 'String constants must end with double quotes'  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
End Class

Thank you for reviewing.

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

looking for guidelines for event driven vs thread

$
0
0
Guys
I'm developing an app which requires access (and communication) between several arduino devices via both serial and also in ethernet. Consider it like a access controller machine, where you need to read ID card (via a COM port) and then you have to do the auth and then you will do some process. A little more on this is like:

1) a vb.net app will be the front end for this
2) an arduino is there for GPIO for actuator control and sensing (just 1 and 0 logic based sense)
3) a smartcard reader
4) A GSM module for SMS alert

Now, the situation is a bit complicated. I can do some on-demand reading and also on-demand writing so far, with kindof a success. I have used timer based. Tick per 3 sec and this is actually making things a bit hard, uncomforting. So, here is the things again:

1) the vb.net app on load, will open a form, named frmMain and will have several buttons for "OPEN" "Close" and some other admin works (like add new card, etc). This form will have also some labels for Status updating. So consider this frmMain as a UI frontend.

2) The UI frontend (aka frmMain) is required to be updated on the GPIO status on a per second basis. So each change will be reflected nearly realtime. There will be some different polling too, like when GPIO is polling per second, GSM can poll per 2/3 sec. This will make the thing reasonable. ON no status update from GSM (send AT and reply OK) for a 30 sec, there will be a alarm generate, (aka, lableAlarm.backcolor=RED) Also on button press, the frmMain will send the arduino (or in some case, GSM) commands. [Please note: the keepalives will not come from arduino/gsm and we will send ping for a pong, and i am happy with that]

3) The card reader reading job is a fully on demand basis, not a pollilng, on pressing the button, it will read smartcard for data, match it and then will allow to do the operation or else it will show a message on status label that card reading failure.

Now, as you can see, some are on demand based and some are polling based, and all of them are sending data for frmMain's labels to be updated accordingly, I finally came out that I should go for threading (each job in a thread) and then each thread to update the frmMain.

Now, all the examples i found in internet, they are having some wiered way of representation, Public class main() and so on... I dont know how to use them in frmMain and also, I'm a bit new in vb.net for specially threading and event baseed works. I worked in arduino (C++) where I have found it keeps looping and I can just call functions when I need. Here it's different.

So I need a bit of a guidance on it... :

1) is my threading thinking OK?
2) how can I achieve it?? [reading say 2 com ports and an ethernet socket in three different thread and update the frmMain accordingly?

Thanks in advanced!!!

[Note: The application MUST run in smooth, not blocking codes!! (which is happening now)]

Help with Dynamic Data

$
0
0
I am currently using AeroWizard's library, more specifically the StepWizardControl. The idea is to allow the user to build a configuration file prior to launching the main application. Part of the process is that I have a button which scans for sensors and then gets their information. Then for each sensor that the user selects, I dynamically create a WizardPage which prepopulates the sensor's IP address and name into a read-only TextBox and prompts for the sensor's username and password.

All of this is fine, but where I run into an issue is when I need to prompt for the sensor's variables. To expand, a sensor reads and writes from something that basically resembles a spreadsheet. A variable is an object that stores a cell's row and column information as well as enumerable data that allows the user (when running the main application) to toggle values in the spreadsheet based. The data also has the possibility to display one thing in the main application and write something completely different to the spreadsheet, an example of this could be where the values: Low, Medium, and High are displayed in the main application but Low represents the Integer value 80 that gets written to the spreadsheet, Medium represents 90, etc.

This is how I am currently representing a Variable, which a sensor has a property that is a List(Of Variable):
Code:

Public Class Variable

    Private _column As String
    ''' <summary>
    ''' Gets or sets the column located in the spreadsheet
    ''' </summary>
    ''' <remarks>Data type is a String to allow for columns like AA, CX, etc.</remarks>
    ''' <returns>String</returns>
    Public Property Column As String
        Get
            Return _column
        End Get
        Set(ByVal value As String)
            If _column <> value Then
                _column = value
                Me.OnColumnChanged()
            End If
        End Set
    End Property

    Private _name As String
    ''' <summary>
    ''' Gets or sets the variable's name
    ''' </summary>
    ''' <returns>String</returns>
    Public Property Name As String
        Get
            Return _name
        End Get
        Set(ByVal value As String)
            If _name <> value Then
                _name = value
                Me.OnNameChanged()
            End If
        End Set
    End Property

    Private _row As UInteger
    ''' <summary>
    ''' Gets or sets the row located in the spreadsheet
    ''' </summary>
    ''' <returns>UInteger</returns>
    Public Property Row As UInteger
        Get
            Return _row
        End Get
        Set(ByVal value As UInteger)
            If _row <> value Then
                _row = value
                Me.OnRowChanged()
            End If
        End Set
    End Property

    Private _values As Dictionary(Of String, String)
    ''' <summary>
    ''' Gets or sets the enumerable values that make up the variable
    ''' </summary>
    ''' <remarks>The Dictionary.Key represents the variable's value that is sent to the spreadsheet and the Dictionary.Value is the variable's value that is displayed to the user</remarks>
    ''' <returns>Dictionary(Of String, String)</returns>
    Public ReadOnly Property Values As Dictionary(Of String, String)
        Get
            Return _values
        End Get
    End Property

    Protected Overridable Sub OnColumnChanged()
        RaiseEvent ColumnChanged(Me, EventArgs.Empty)
    End Sub

    Protected Overridable Sub OnNameChanged()
        RaiseEvent NameChanged(Me, EventArgs.Empty)
    End Sub

    Protected Overridable Sub OnRowChanged()
        RaiseEvent RowChanged(Me, EventArgs.Empty)
    End Sub

    Public Event ColumnChanged(ByVal sender As Object, ByVal e As EventArgs)
    Public Event NameChanged(ByVal sender As Object, ByVal e As EventArgs)
    Public Event RowChanged(ByVal sender As Object, ByVal e As EventArgs)

End Class

Initially, I planned on creating the dynamic WizardPage to include a DataGridView and a BindingNavigator where the BindingNavigator will launch a dialog Form to prompt for insert/update commands for variables (see screenshot).
Name:  dynamic wizard page.jpg
Views: 43
Size:  19.0 KB

But how would I keep track of the dynamic data? Keep in mind that whenever I create the BindingNavigator, I am passing a True value in the constructor so that the standard items are created, but since I want a dialog Form to appear when the user clicks on insert I will also need to override the default behavior of when the InsertButton is clicked so that rather than creating a new blank row it launches the dialog instead. Also, I tried to bind the underlying BindingSource of the BindingNavigator to the sensor's Variables property, but that fails because it doesn't implement IContainer.

I guess I just need y'all's input on what y'all would do in this situation before I started really doing some coding on the dynamic WizardPages.
Attached Images
 

VS 2012 Critics in visual basic

$
0
0
I've been programming or should I say learning programming with V.b.Net and when I tell someone that I use V.b to write my programs, they'll say that that is a beginner language. They try to mock me or make fun of me that V.b is a 'Small Children`s' language. They criticize the language a lot saying instead of I learning Java or C# or any other better language I'm wasting my time. But what's actually wrong with the language?
Viewing all 27494 articles
Browse latest View live


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