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

VS 2017 [RESOLVED] Beginner Please Need Help

$
0
0
Code:

Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim Grade As Double
        Grade = CDbl InputBox("Enter The Grade")

        If Grade < 50 Then
            MsgBox("F")
        ElseIf Grade >= 50 < 60 Then
            MsgBox("D")
        ElseIf Grade >= 60 < 70 Then
            MsgBox("C")
        ElseIf Grade >= 70 < 80 Then
            MsgBox("B")
        ElseIf Grade >= 80 < 90 Then
            MsgBox("A")
        ElseIf Grade >= 90 Then
            MsgBox("A+")
        Else
            MsgBox("Please Input A Valid Grade")
        End If


    End Sub
End Class

can someone please help me or guide me what im doing wrong with my code im a begginer in coding and i can't get the result i want which is when you input a grades it will display the remarks?

VS 2017 [RESOLVED] Beginner Need a Guide

$
0
0
Name:  Screenshot (20).jpg
Views: 110
Size:  16.2 KB

what do i need to do so my output would be like this can help me please

this is my code

Code:

Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Dim strLength As String = TextBox1.Text
        MessageBox.Show("Output : " & strLength.Length.ToString)

    End Sub
End Class

what do i need to do so my output would be like this can help me please

Name:  Screenshot (19).jpg
Views: 106
Size:  8.5 KB
Attached Images
  

[RESOLVED] Solution Explorer

$
0
0
Hello everyone. I am a new user in this forum, and I've begun studying VB.NET 2019. I have a large application in my mind, which i want to break it into several projects.
For example for the X company solution there will be a project that keeps record the company's structure, employee information, employee departments as well as login mechanism, user rights. Other projects will be assigned to each department according to its duties and job and will be included to the solution.
So, If is place these projects in the same solution, is it possible for these projects to integrate each other? For example what about if i want to pass the login user information from the login project, to his department work interface project and so on? And if this can be done through the RDMS, how about the scope of each project variables? Is there any way variables of X project to be accesible from Y project?


Thank you in advance.

VS 2019 Text.Encoding.Getbytes Works in WPF not Forms

$
0
0
Hi Everyone

Can anybody tell me why this line of code will work in wpf but not forms?
Background have a user name textbox that in need to turn into some bytes then add crc to send to some
electronics. Im trying to borrow code i wrote in WPF and use it for a quick project in Forms

Turns out it wont be as quick as I thought lol.

Error is Encoding is not a member of string

Thanks in advance

Code:

        Dim UserName As Byte() = (Text.Encoding.ASCII.GetBytes(USR_Box.Text)).ToArray

Read from Excel file and release COM

$
0
0
Hi, I am pretty new at opening and reading from Excel files in VB.NET. I have this code where I am simply reading in a few values from a single row and then closing the Excel file. My problem is that I continue to get an error:
Code:

System.Runtime.InteropServices.COMException: 'Exception from HRESULT: 0x800401A8'
It must be something about either opening or closing Excel but it is driving me crazy and I cannot seem to figure out what is happening. Here is the code that I have right now. Thanks for any help provided.

My error triggers on this line:
Code:

If worksheet.Cells(X, ColumnNumber).value = String2Search4 Then
Code:

Sub ExternalData()

        Dim APP As New Excel.Application
        Dim worksheet As Excel.Worksheet
        Dim workbook As Excel.Workbook
        Dim String2Search4 As String = txtPartNum.Text  'String to search for.
        Dim ColumnNumber As Integer = 1

        Try
            APP = CreateObject("Excel.Application")
            workbook = APP.Workbooks.Open("C:\temp\mag-kpi.xlsx")
            worksheet = workbook.Worksheets("Sheet1")
        Catch ex As Exception
            Dim unused = MsgBox("Error locating external data file. Locate file and try again!", vbExclamation, "")
            Exit Sub
        End Try

        'loop through each row
        For X As Integer = 1 To worksheet.Rows.Count Step 1
            'check if the cell value matches the search string.
            If worksheet.Cells(X, ColumnNumber).value = String2Search4 Then    <<<< this is where I get the above error.
                txtDataAnum.Text = String2Search4
                txtDataStart.Text = worksheet.Cells(X, ColumnNumber + 1).value
                txtDataComplete.Text = worksheet.Cells(X, ColumnNumber + 2).value
                txtDataQty.Text = worksheet.Cells(X, ColumnNumber + 3).value
                cmbLateStart.Text = dataReason

                If txtDataStart.Text < DateTime.Today And dataReason = "" Then
                    cmbLateStart.Visible = True
                    lblLateStart.Visible = True
                End If

            End If

            workbook.Close()
            APP.Quit()

        Next

        APP = Nothing
        worksheet = Nothing
        workbook = Nothing

    End Sub

vb.net MEMORY problems

$
0
0
Hi

Which is less memory for vb.net program?

dim i as integer (10 time dim as integer) or an array with 10 item (integer)

same in string
dim i as string
dim i as string
...
vs
array with 10 item as string?

VS 2019 [RESOLVED] Text.Encoding.Getbytes Works in WPF not Forms

$
0
0
Hi Everyone

Can anybody tell me why this line of code will work in wpf but not forms?
Background have a user name textbox that in need to turn into some bytes then add crc to send to some
electronics. Im trying to borrow code i wrote in WPF and use it for a quick project in Forms

Turns out it wont be as quick as I thought lol.

Error is Encoding is not a member of string

Thanks in advance

Code:

        Dim UserName As Byte() = (Text.Encoding.ASCII.GetBytes(USR_Box.Text)).ToArray

Automation???

$
0
0
Some of you are already familiar with my attempts to write a GroceryList program. I wrote it a long time ago in VB6 using 40 Listboxes, 40 RadioButtons, and 40 Buttons. I got a lot of flack on this forum about using so many controls. Now I rewriting it in VB.net VS2019. I'm using 4 Listboxes, 40 RadioButtons, and 16 Buttons, and saving the items in general in List Arrays.

But here is the problem. I am not using automation because I don't know how. The program IS working, but it's getting really long because I have to make a subroutine for each list with each one just having a different number next to the word "List" and/or "Listbox". And I'm having to do this over and over!!! How do I make a subroutine that will handle each one with the important info sent as arguments?

Here is some examples of what I'm talking about.

Example 1
Code:

    Dim list0 As New List(Of String)
    Dim list1 As New List(Of String)
    Dim list2 As New List(Of String)
    Dim list3 As New List(Of String)
    Dim list4 As New List(Of String)

Example 2
Code:

  Dim objWriter As New StreamWriter("C:\Grocery List\GList2.TXT")

        objWriter.WriteLine("00;*;" & RadioButton0.Text) '
        For Each Item As String In list0
            objWriter.WriteLine(Item) '
        Next

        objWriter.WriteLine("01;*;" & RadioButton1.Text) '
        For Each Item As String In list1
            objWriter.WriteLine(Item) '
        Next

        objWriter.WriteLine("02;*;" & RadioButton2.Text) '
        For Each Item As String In list2
            objWriter.WriteLine(Item) '
        Next

Example 3
Code:

Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton1.CheckedChanged

        If RadioButton1.Checked = True Then
            ListBox0.Items.Clear()
            ListBox0.Items.AddRange(list1.ToArray)
        Else
            list1.Clear()
            For X As Integer = 0 To ListBox0.Items.Count - 1
                If ListBox0.GetSelected(X) Then
                    list1.Add("+" & ";" & ListBox0.Items.Item(X).ToString)
                Else
                    list1.Add("-" & ";" & ListBox0.Items.Item(X).ToString)
                End If
            Next
        End If
    End Sub

    Private Sub RadioButton2_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton2.CheckedChanged

        If RadioButton2.Checked = True Then
            ListBox0.Items.Clear()
            ListBox0.Items.AddRange(list2.ToArray)
        Else
            list2.Clear()
            For X As Integer = 0 To ListBox0.Items.Count - 1
                If ListBox0.GetSelected(X) Then
                    list2.Add("+" & ";" & ListBox0.Items.Item(X).ToString)
                Else
                    list2.Add("-" & ";" & ListBox0.Items.Item(X).ToString)
                End If
            Next
        End If
    End Sub

Thanks

Database login in vb

$
0
0
Hello everyone, my name is Ciro and I work in a small company in Italy, I would like to ask you for help,
I would like to ask you if you can tell me how I can create a database login with a simple vb windows form program.
I try to explain myself better ... we are doing a project where a user makes a database access through the credentials written in it.
let me know if you can help me, thanks in advance for the time dedicated to me.
Ciro:)

VS 2019 No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE))

$
0
0
I was running 16.8.5

Was getting this error when trying to create a new project.
I also noticed my toolbar was acting glitchy with no icons.
Rebooting did not fix it.

I updated to 16.8.6 and the problem went away.

Anyone else get this recently ?

How to Revert Identity Impersonation to original user

$
0
0
I'm using the following code to set the identity impersonation at runtime, but when it calls undoImpersonation() it sets the identity to IIS APPPOOL\DefaultAppPool. Instead of DefaultAppPool, how can I revert back to the original user identity?

Code:

Dim LOGON32_LOGON_INTERACTIVE As Integer = 2
Dim LOGON32_PROVIDER_DEFAULT As Integer = 0
Dim impersonationContext As WindowsImpersonationContext

Declare Function LogonUserA Lib "advapi32.dll" (ByVal lpszUsername As String, _
                        ByVal lpszDomain As String, _
                        ByVal lpszPassword As String, _
                        ByVal dwLogonType As Integer, _
                        ByVal dwLogonProvider As Integer, _
                        ByRef phToken As IntPtr) As Integer

Declare Auto Function DuplicateToken Lib "advapi32.dll" ( _
                        ByVal ExistingTokenHandle As IntPtr, _
                        ByVal ImpersonationLevel As Integer, _
                        ByRef DuplicateTokenHandle As IntPtr) As Integer

Declare Auto Function RevertToSelf Lib "advapi32.dll" () As Long
Declare Auto Function CloseHandle Lib "kernel32.dll" (ByVal handle As IntPtr) As Long

Public Sub Page_Load(ByVal s As Object, ByVal e As EventArgs)
    If impersonateValidUser("username", "domain", "password") Then
        'Insert your code that runs under the security context of a specific user here.
        undoImpersonation()
    Else
        'Your impersonation failed. Therefore, include a fail-safe mechanism here.
    End If
End Sub

Private Function impersonateValidUser(ByVal userName As String, _
ByVal domain As String, ByVal password As String) As Boolean

    Dim tempWindowsIdentity As WindowsIdentity
    Dim token As IntPtr = IntPtr.Zero
    Dim tokenDuplicate As IntPtr = IntPtr.Zero
    impersonateValidUser = False

    If RevertToSelf() Then
        If LogonUserA(userName, domain, password, LOGON32_LOGON_INTERACTIVE,
                    LOGON32_PROVIDER_DEFAULT, token) <> 0 Then
            If DuplicateToken(token, 2, tokenDuplicate) <> 0 Then
                tempWindowsIdentity = New WindowsIdentity(tokenDuplicate)
                impersonationContext = tempWindowsIdentity.Impersonate()
                If Not impersonationContext Is Nothing Then
                    impersonateValidUser = True
                End If
            End If
        End If
    End If
    If Not tokenDuplicate.Equals(IntPtr.Zero) Then
        CloseHandle(tokenDuplicate)
    End If
    If Not token.Equals(IntPtr.Zero) Then
        CloseHandle(token)
    End If
End Function

Private Sub undoImpersonation()
    impersonationContext.Undo()
End Sub

Textbox changes and Checkbox.Checked

$
0
0
Gud evening members , this is my second post
i did a Duct size Calculator program for me in VB.net 2010,
the Calculator is working

just need simpilyfication of this code if some one help to reduce this code simple very helpful

this is the code:

Code:

'When Flow Changed
    Private Sub txtQ_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtQ.TextChanged

        If CheckBox1.Checked And CheckBox2.Checked Then
            Airflow_HeadLoss()
        Else
        End If

        If CheckBox1.Checked And CheckBox3.Checked Then
            Airflow_Velocity()
        Else
        End If

        If CheckBox1.Checked And CheckBox4.Checked Then
            Airflow_Diameter()
        Else

        End If

    End Sub

    'When Headloss Changed
    Private Sub txtHf_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtHf.TextChanged

        If CheckBox1.Checked And CheckBox2.Checked Then
            Airflow_HeadLoss()
        Else
        End If

        If CheckBox2.Checked And CheckBox3.Checked Then
            Headloss_Velocity()
        Else
        End If

        If CheckBox2.Checked And CheckBox4.Checked Then
            Headloss_Diameter()
        Else
        End If

    End Sub

    'When Velocity Changed
    Private Sub txtV_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtV.TextChanged

        If CheckBox1.Checked And CheckBox3.Checked Then
            Airflow_Velocity()
        Else
        End If

        If CheckBox2.Checked And CheckBox3.Checked Then
            Headloss_Velocity()
        Else
        End If

        If CheckBox3.Checked And CheckBox4.Checked Then
            Velocity_Diameter()
        Else
        End If

    End Sub

    'When Diameter Changed
    Private Sub txtD_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtD.TextChanged

        If CheckBox1.Checked And CheckBox4.Checked Then
            Airflow_Diameter()
        Else
        End If

        If CheckBox2.Checked And CheckBox4.Checked Then
            Headloss_Diameter()
        Else
        End If

        If CheckBox3.Checked And CheckBox4.Checked Then
            Velocity_Diameter()
        Else
        End If

        Duct_Size()
        Duct_Data()

    End Sub

How to convert VBA to VB.NET? Catia macro?

$
0
0
I created my code of new catia macro with Visual Basic Editör included CATIA. But I have to transiation to VB.NET.

How to convert VBA to VB.NET?

VS 2019 Error Codes while running an app

$
0
0
#1
I am trying to run an app with 4 window forms however i get several errors.
This is a very simple app. Not sure why these errors..... new at this so if anyone can please guide would be great!!!!!


Severity Code Description Project File Line Suppression State
Error BC30002 Type 'Global.Microsoft.VisualBasic.ApplicationServices.User' is not defined. TASK MASTER C:\Users\anshika\source\repos\TASK MASTER\TASK MASTER\vbc 1
Severity Code Description Project File Line Suppression State
Error BC30002 Type 'Global.Microsoft.VisualBasic.Devices.Computer' is not defined. TASK MASTER C:\Users\anshika\source\repos\TASK MASTER\TASK MASTER\vbc 1 Active
Severity Code Description Project File Line Suppression State
Error BC30002 Type 'Global.Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase' is not defined. TASK MASTER C:\Users\anshika\source\repos\TASK MASTER\TASK MASTER\vbc 1 Active
Severity Code Description Project File Line Suppression State
Error BC30456 'ApplicationServices' is not a member of 'Microsoft.VisualBasic'. TASK MASTER C:\Users\anshika\source\repos\TASK MASTER\TASK MASTER\My Project\Application.Designer.vb 26 Active
Error BC30456 'IsSingleInstance' is not a member of 'MyApplication'. TASK MASTER C:\Users\anshika\source\repos\TASK MASTER\TASK MASTER\My Project\Application.Designer.vb 27 Active
Error BC30456 'EnableVisualStyles' is not a member of 'MyApplication'. TASK MASTER C:\Users\anshika\source\repos\TASK MASTER\TASK MASTER\My Project\Application.Designer.vb 28 Active
Error BC30456 'SaveMySettingsOnExit' is not a member of 'MyApplication'. TASK MASTER C:\Users\anshika\source\repos\TASK MASTER\TASK MASTER\My Project\Application.Designer.vb 29 Active
Error BC30456 'ShutDownStyle' is not a member of 'MyApplication'. TASK MASTER C:\Users\anshika\source\repos\TASK MASTER\TASK MASTER\My Project\Application.Designer.vb 30 Active
Error BC30456 'ApplicationServices' is not a member of 'Microsoft.VisualBasic'. TASK MASTER C:\Users\anshika\source\repos\TASK MASTER\TASK MASTER\My Project\Application.Designer.vb 30 Active

DataTable Select | Grouping Data | Is there a Generic Method?

$
0
0
Dear all,

I am building a reporting tool which groups data from two columns of a DataTable and then Sums/Counts/Gets the Average of the third column.

The following code below worked until the data columns changed from String to XXX (e.g. Integer, Decimal, Date, etc...).

Is there a dynamic way to writing the following code so that it handles any column type? I fear my only solution at present is to build a unique routine for each combination of the possible data types.

Sample Code:
iResult = (From NewTable In Me.xDataTable.AsEnumerable
Group NewTable By AAA = NewTable.Field(Of String)(xBBB), BBB = NewTable.Field(Of String)(xAAA) Into g = Group
Select New With {Key AAA,
.QQQ = g.Sum(Function(r) r.Field(Of Integer)(xQQQ)),
.BBB = BBB}).OrderBy(Function(tkey) tkey.AAA).ToList()



Any help would be very much appreciated.
MJC

VS 2017 Title Bars Overlapping When Full Screen and Opening another application

$
0
0
We have a VB.Net application that opens Microsoft Excel, Outlook.
When the base application opens Excel or Outlook, the title bars become garbled and unusable ( See 3 example in attachement/photo)

We run windows 10 Pro 1809 on Dell 3500 laptops

Has anyone experienced this before and found a way around it?
Attached Images
 

VS 2019 Add printer in windows 10 problem

$
0
0
  • Im having problems with adding printer's in windows 10
  • After adding the port, the program just crash
  • The code im using works very well in windows 7
  • Can anybody help? Thanks



'SETS LOAD DRIVERS PRIVILEGE.
Dim strComputer As String
Dim objWMIService As Object
strComputer = "."
objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\" & strComputer & "\root\cimv2")

'SETS PRINTER PORT
Dim objNewPort = objWMIService.get("Win32_TCPIPPrinterPort").SpawnInstance_
objNewPort.Name = "10.71.197.217"
objNewPort.Protocol = 1
objNewPort.HostAddress = "10.71.197.217"
objNewPort.PortNumber = 9100
objNewPort.SNMPEnabled = False
objNewPort.Put_

'INSTALL DRIVERS
Dim objDriver = objWMIService.Get("Win32_PrinterDriver")
objWMIService.Security_.Privileges.AddAsString("SeLoadDriverPrivilege", True)
objDriver.Name = "Canon iR2520 UFRII LT"
objDriver.SupportedPlatform = "Windows NT x86"
objDriver.Version = "3"
objDriver.FilePath = "$(ProjectDir)..\..\Drivers\Canon\Canon IR2520\x64\Driver"
objDriver.Infname = "CNLB0MA64.INF"
Dim intResult = objDriver.AddPrinterDriver(objDriver)

'SETS PRINTER TO THE PORT
Dim objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_
objPrinter.DriverName = "Canon iR2520 UFRII LT"
objPrinter.PortName = "10.71.197.217"
objPrinter.DeviceID = "Canon 2520 test UFRII W10"
objPrinter.Location = "TTEST W10"
objPrinter.Default = 1
objPrinter.Network = True
objPrinter.Shared = False
objPrinter.Put_

VS 2010 Deboger OK , Released Not Finish

$
0
0
When I run my code thru the déboger the program run all the way to the end.
When I run the released program, it does not go all the way.
Where should I search?
Thank you

Visual Basic net files tutorial

$
0
0
There appears to be many different ways to deal with reading, writing, checking if a file exist etc.
Is there a good tutorial that deals with all of those ways?

Application.StartupPath is not working vb.net

$
0
0
Dear All

I used the
Code:

Dim Path As String = Application.StartupPath & "\Main_Master_VB.xls"
in vb.net Application and it worked very well but when I used it in another vb.net application with the same references it is not working it gives the following Error:

Reference to a non-shared member requires an object reference, I do not know what is the missing reference ?

Thanks your support

Moheb Labib
Viewing all 27338 articles
Browse latest View live