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

[RESOLVED] problem with sum in diferent many tables

$
0
0
I'am using vb2008 - ms access
i tried this code to sum values from three tables
and i put them in Form load
SumComR3()
SumMnyD()
SumMnyPT()
the problem is when any of these three tables has no any record, another code of another table don't sum any value
it means when table6 has no record. the s SumMnyD and SumMnyPT don't sum the values in table5 and table4
Code:

Public Sub SumComR3()
        conn.Open()
        Dim cmd5 As New OleDbCommand("select sum(ComR3) from Table6", conn)
        Form7.txtComR3.Text = cmd5.ExecuteScalar
        conn.Close()
    End Sub

    Public Sub SumMnyD()
        conn.Open()
        Dim cmd6 As New OleDbCommand("select sum(MnyD) from Table5", conn)
        Form7.txtMnyD.Text = cmd6.ExecuteScalar
        conn.Close()
    End Sub

    Public Sub SumMnyPT()
        conn.Open()
        Dim cmd7 As New OleDbCommand("select sum(MnyP) from Table4 where KindP = 'somthing' ", conn)
        Form7.txtMnyPT.Text = cmd7.ExecuteScalar
        conn.Close()
    End Sub


VS 2017 Disposing variables and objects that contains sensitive data

$
0
0
I made a class to retrieve sensitive encrypted data from a file.

The class ClassSecret have a ReadOnly Property that return the sensitive data into a Dictionary.
The class DataProtector contains the function to decrypt the encrypted data.

Code:

Imports System.Web.Script.Serialization

Public Class ClassSecret
    Private Shared ReadOnly byteArray As Byte() = {0, 0} 'The sensitive data

    Private Shared ReadOnly Property Secrets As Dictionary(Of String, String)
        Get
            Dim dp As DataProtector = Nothing
            Dim tmpSecretsString As String
            Dim tmpSecrets As Dictionary(Of String, String)
            Dim serializer As JavaScriptSerializer = Nothing

            Try
                dp = New DataProtector
                tmpSecretsString = dp.ProtectedDataToString(byteArray)
                serializer = New JavaScriptSerializer()
                tmpSecrets = serializer.Deserialize(Of Dictionary(Of String, String))(tmpSecretsString)
                Return tmpSecrets
            Finally
                dp = Nothing
                tmpSecretsString = Nothing
                tmpSecrets = Nothing
                serializer = Nothing
            End Try

        End Get
    End Property

End Class

Public Class DataProtector
    Public Function ProtectedDataToString(ByVal data As Byte()) As String
        'Do some stuff
        Dim newString As String = "{""decrypted"":""data""}"
        Return newString
    End Function
End Class

I don't have much knowledge in computer science. I'm not sure if the variables values are stored somewhere in memory (and then can be accessed by unauthorized app) after I get the "Secrets" Property value from somewhere else in my program.
That's why I used a Try Finally to make the variables and objects egual to Nothing after the value of the property is returned.
I'm not using the Using statement since my class DataProtector don't have IDisposable implemented.

I may overcomplicate everything here. Is that Finally statement to make variables egual to Nothing is usefull, or all the variables are somewhat disposed automatically after the Get method returned the value as in the following code?

Code:

Private Shared ReadOnly Property Secrets As Dictionary(Of String, String)
        Get
            Dim tmpSecretsString As String = New DataProtector().ProtectedDataToString(byteArray)
            Dim tmpSecrets As Dictionary(Of String, String) = New JavaScriptSerializer().Deserialize(Of Dictionary(Of String, String))(tmpSecretsString)

            Return tmpSecrets
        End Get
    End Property

Thanks

How do I send an existing text file from my folder to a printer ?

$
0
0
Hi,

I've been trying to find how to send an existing text file to my printer... in an application.
I can obviously use 'Process.Start' to open the file on screen, and then send it to the printer from there, but I'd like to be able to do something similar to 'Process.Start' to send it to the printer.

All I can find in great detail is how to write the file, add to a file, read-in a file... I have the files, I just want to print 'em.


Poppa

VISUAL STUDIO 2017 how to connect 2 computers to same program?

$
0
0
hey
i have a client with 2 computers in his business.
now he wants to work with the same programm on both computers with same database.
i want to install the program on the main computer and from another computer in the same network will work on it at the same time.is it possible to do so?
need some proffesional advices.
thank you :)
salsa

[RESOLVED] Processing Files in a folder in sequence

$
0
0
I would really appreciate your help with the following interesting issue:
I am developing a Visual Basic program in MS Visual Studio version 16.3, as follows:

I have a list of several files in a folder on the computer. Each of the files in this folder contains customer information. Each file, referring to a separate customer, has exactly the same layout and contains the same information (e.g. Customer first name, Customer surname, Company name, Email, etc.).

I have extracted this customers files via a separate tool and placed them in the folder.

To process the customers information in my own Visual Basic program, ideally, I would like to have all my customers information in one ‘consolidated’ file instead of having each customer in a separate file. However, for reasons beyond the scope of the current discussion, this is not possible!

I have to deal with the situation as it is. Therefore, I need my own Visual Basic to perform the following steps:

1 – Access the folder where the customers files are stored (this is always the same path. If need be I can hard-code the path in the program)

2 – Access each file in the folder in turn. Open, read and process the customer information in the file. Once done, close the file and proceed to the next file containing the information for the next customer.

3 – Exit when the last file in the folder is processed.

I would really appreciate your help/advise with this rather intriguing problem! The prime question is how I can separate each file separately...

[RESOLVED] How do I send an existing text file from my folder to a printer ?

$
0
0
Hi,

I've been trying to find how to send an existing text file to my printer... in an application.
I can obviously use 'Process.Start' to open the file on screen, and then send it to the printer from there, but I'd like to be able to do something similar to 'Process.Start' to send it to the printer.

All I can find in great detail is how to write the file, add to a file, read-in a file... I have the files, I just want to print 'em.


Poppa

State of Web API

$
0
0
I've spent the past few days reading about ASP.NET/Web API/Katana/ASP.NETCore and so on. The terrain seems to be shifting every couple years, and MS is reinforcing that feeling. At this point, after all the reading I have done, I'm not sure what is current and what is not, except that I'm pretty sure that I'm not.

I'm using Web API in 4.7.2. From what I have seen and tried, that can use some ASP.NETCore, but not everything. There are plenty of packages that won't install on framework, and require Core 2.x or 3.x.

Meanwhile Katana seems current, while ASP.NET appears somewhat deprecated by MS, though still viable. Does that sound right?

Ultimately, I'm looking to consume JWT tokens in a FW 4.7.2 application. There appears to be an abundance of means, none of which appear all that well documented. It looks like an OWIN approach using Microsoft.Owin.Security.Jwt would be both reasonably current, and likely to be sustainable for a few years. It also looks like VB.NET might be in Core 3.x by this fall/winter, which....actually complicates the situation, as one alternative was always to move over to C# for this and just build it in Core. I'd prefer to stick with FW for these reasons:

1) The API is already written, tested, and deployed, so a re-write holds little appeal.
2) I think it might be a bit less of a black box, though not by much.

Basically, I've found a whole lot of dubious articles on consuming/validating JWT tokens, along with a few that are pretty good. I'd probably go with one that has reasonably good documentation, which is why I am currently favoring Katana. However, I thought I'd ask for suggestions here. The amount of weak documentation is impressive. Some folks could use an editor...including me, so I'm sympathetic to the situation, but still....

So, any suggestions?

linq query to sum total items

$
0
0
I,i have a little program that retrieves railway reservations for groups.

The object for the program is to know :
a) how many people load and unload that train,selecting a particular station (ex rome,11 loaded,89 unloaded)
b) how many people load a specific car (ex car 5-10 passenger,car 7-11 passenger)
c) how many destinations and people selecting a particular station (ex from rome,11 passenger to florence,18 to milan,etc)
in another thread i had linq suggestion, so i create a datatable filling it by a json response from a website.
made this code to retrieve all stations served by the train :
Code:

With treno1
        .Columns.Add("Partenza", System.Type.GetType("System.String"))
        .Columns.Add("Arrivo", System.Type.GetType("System.String"))
        .Columns.Add("PNR", System.Type.GetType("System.String"))
        .Columns.Add("Classe", System.Type.GetType("System.String"))
        .Columns.Add("Cognome", System.Type.GetType("System.String"))
        .Columns.Add("Carrozza", System.Type.GetType("System.String"))
        .Columns.Add("Posto", System.Type.GetType("System.String"))
        .Columns.Add("Nome", System.Type.GetType("System.String"))
        .Columns.Add("Treno", System.Type.GetType("System.String"))
        .Columns.Add("ID prenotazione", System.Type.GetType("System.String"))
End With
Dim stazioni As New List(Of String)

For Each item As JProperty In data
    item.CreateReader()

    For Each msg As JObject In item.Values
        treno1.Rows.Add(msg("departureLocationName"), msg("arrivalLocationName"), msg("pnrCode"), msg("serviceLevel"), msg("lastName"), msg("wagon"), msg("seat"), msg("firstName"), msg("transportMeanName"), msg("Id"))
    Next
Next

Dim partenzaStations = From n In treno1.AsEnumerable()
                      Where n.Field(Of String)("Partenza") IsNot Nothing
                      Select n.Field(Of String)("Partenza")

Dim arrivoStations = From n In treno1.AsEnumerable()
                    Where n.Field(Of String)("Arrivo") IsNot Nothing
                    Select n.Field(Of String)("Arrivo")

Dim stations = partenzaStations.Concat(arrivoStations).Distinct().OrderBy(Function(s) s).ToArray()

ComboBox1.DataSource = stations.ToArray
ComboBox1.SelectedIndex = -1

but now how to know how many people is loading a station ? and how many people in CERTAIN station are going to a destination ? (for example in rome : 10 to florence,10 to bologna ,5 to milan)
i tried this code but there's a logic error :


Code:

Dim destinazione = From n In treno1.AsEnumerable()
                  Where n.Field(Of String)("Partenza") = ComboBox1.SelectedValue
                  Select n.Field(Of String)("Arrivo")

Dim destinazioni = (destinazione.Distinct).ToList

Dim totalepax = From n In treno1.AsEnumerable()
                Where n.Field(Of String)("Partenza") = ComboBox1.SelectedValue
Aggregate destinazioni

which is the right code ?

Determine Target CPU | Microsoft Access OleDB

$
0
0
Hi,

I have an application which I've developed which is used across a big organization. As such, there are a variety of PCs with different OS being used. As such, the ODBC connection doesn't always work unless the user is using the correct bit version of the application. I receive an error message when I try to connect to access when the wrong Target CPU has been selected.

My proposed solution is to deploy both versions of the application (V_x86 & V_64) and include a Launch (startup) application which would then load the applicable exe to match the user's PC settings.

Would anyone know if there is a function/property which would I could call/read to determine the which of the two exes (V_x86 & V_64) to run for a given user?

Thank you in advance for any guidance.
Kind regards,
MJC

Weird Screen Redraw Issue

$
0
0
Something odd is going on with my dropdown menus when i hover over them.
This only happens when I have this datagridview on the screen.

If I have 31k records loaded and I hover over a menu.... it doesn't finish drawing the menu for about 5 seconds.

But, if a load only 200 records.... the menu redraws immediately.

What is happening to the painting of my screen because of the datagridview.

Like I said, it only does this when I have the datagridview visible and loaded with a lot of records.


And yes, I do close the sqlite database connection after loading.

This does this even after 10 minutes after loading records.

It seems to be a screen redraw issue.


But, how do fix this? Or can I?

See below screen

Name:  biblenotes5.jpg
Views: 29
Size:  16.7 KB


Thanks
Attached Images
 

VS 2019 Problem switching source on Acrobat Viewer

$
0
0
Hi

I've embedded the usual AxAcro pdf viewer in a form and am using the code below to change the pdf displayed when I press a button:

Code:

Public Class Form1

    Public temp_counter = 1

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

        Threading.Thread.Sleep(1000)

        Acro1.src = ""

        Select Case temp_counter

            Case 1 : Acro1.src = "C:\test 3\1.pdf"

            Case 2 : Acro1.src = "C:\test 3\2.pdf"

            Case 3 : Acro1.src = "C:\test 3\3.pdf"

            Case 4 : Acro1.src = "C:\test 3\4.pdf"

            Case 5 : Acro1.src = "C:\test 3\5.pdf"

            Case 6 : Acro1.src = "C:\test 3\6.pdf"

            Case 7 : Acro1.src = "C:\test 3\7.pdf"

            Case 8 : Acro1.src = "C:\test 3\8.pdf"

            Case 9 : Acro1.src = "C:\test 3\9.pdf"

        End Select

        temp_counter += 1
        If temp_counter = 10 Then temp_counter = 1

    End Sub
End Class

I'm getting an issue after about 7 switches. My form disappears from view as well as the taskbar (I'm this in the VS debug environment) and the program keeps running - I have to stop it manually.

I added the 1 second sleep to see if the control needed a bit of breathing space or something, but it doesn't help.

I can confirm none of the pdfs give an error when viewed outside of vb, they are not corrupt or anything - I've tried it just switching between 1.pdf and 2.pdf and I still get the same issue. I've also tried it with different pdfs - just some dummies I created from word - so I'm as confident as I can be that it's not the pdfs themselves that are to blame.

I'm scratching my head a bit here as there's no error message to go on.

Is there some other way I need to reset Acro1 between source changes?

Can anyone shine any light on this for me?

Thanks!

UPDATE - I've tried using the webbrowser control instead and it works without any problems. I would prefer to use the pdf viewer however, as it provides a cleaner interface without any menus from whatever the default pdf viewer features.

[RESOLVED] I have a problem with 'interpolated-strings'.

$
0
0
I am trying to re-code...
Code:

    Private Function Resolve(ByVal secs As Int32) As String
        Dim h, m As Int32 ', txt As String
        h = 0 : m = 0
        While secs > 3599
            h += 1
            secs -= 3600
        End While
        While secs > 59
            m += 1
            secs -= 60
        End While
        txt = h.ToString("00") & ": "
        txt &= m.ToString("00") & ": "
        txt &= secs.ToString("00")
        Return txt
    End Function

...using interpolated-strings code from Microsoft thus:
Code:

    Private Function Resolve(ByVal secs As Int32) As String
        Dim hrs, mins As Int32 ', txt As String
        hrs = 0 : mins = 0
        While secs > 3599
            hrs += 1
            secs -= 3600
        End While
        While secs > 59
            mins += 1
            secs -= 60
        End While
        'Return $"{h:h2}: {m:m2}: {secs:t2}"
        'Return $"{h}: {m}: {secs}"
        'Return $"{h:hh}: {m:mm}: {secs:tt}"
        Return $"{hrs}: {mins}: {secs}"
        'Return $"{hrs:h2}: {mins:m2}: {secs:t2}"
        'Return $"{hrs:hh}: {mins:mm}: {secs:tt}"
        'Return $"{hrs:hh2}: {mins:mm2}: {secs:tt2}"
    End Function

I thought I had a problem because I was using just 'h' and 'm' for the string variables so I changed 'em. I've left all the options I've tried as a record.

Using: Return $"{h:h2}: {m:m2}: {secs:t2}" (original code)
utnor: Return $"{hrs:h2}: {mins:m2}: {secs:t2}"
I get an error:
Quote:

System.FormatException: 'Format specifier was invalid.'
Using: Return $"{h:hh}: {m:mm}: {secs:tt}" (original code)
utnor: Return $"{hrs:hh}: {mins:mm}: {secs:tt}"
utnor: Return $"{hrs:hh2}: {mins:mm2}: {secs:tt2}"
the function returns: "hh: mm: tt", "hh: mm: tt" and "hh2: mm2: tt2" respectively.

Using: Return $"{h}: {m}: {secs}" (original code)
utnor: Return $"{hrs}: {mins}: {secs}"
the function returns: (for example) "0: 9: 6", where I expected "00: 09: 06".

Maybe because I want the colon between the first two elements it's causing confusion?
Although trying a dash instead of the colon, (Return $"{hrs:hh}- {mins:mm}- {secs:tt}) I just get "hh- mm- tt".

What am I doing wrong ?


Poppa

VB 2008 How to bold a date from a monthcalendar after a left mouse click

$
0
0
Hello,

The code below does not seem to work:
Code:

Private Sub MonthCalendarVacation_DateSelected(ByVal sender As Object, ByVal e As System.Windows.Forms.DateRangeEventArgs) Handles MonthCalendarVacation.DateSelected
        MonthCalendarVacation.AddBoldedDate(e.Start.Date())
        Invalidate()
End Sub

Do you have any ideas?

Thanks in advance.

VS 2017 [RESOLVED] For each Next Loop

$
0
0
I am looking for some help in making this code better it works but it seems to be awfully slow. I am VB hobbyist and I suspect it is not written well.

Code:

Public Function GEOCode() As Boolean


        For Each address In GetNullAddressList()
            For i As Integer = 0 To dtlist.Rows.Count - 1

                Dim StreetAddress As String = CStr(dtlist.Rows(i)("FullStreetAddress"))
                Dim City As String = CStr(dtlist.Rows(i)("City"))
                Dim State As String = CStr(dtlist.Rows(i)("State"))
                Dim Zip As String = CStr(dtlist.Rows(i)("ZipCode"))
                SearchAddress = GetAddress(StreetAddress, City, State, Zip)
                dtlist.Rows(i).Item("Latitude") = CStr(SearchAddress.Latitude)
                dtlist.Rows(i).Item("Longitude") = CStr(SearchAddress.Longitude)
            Next
            ProgressBar3.PerformStep()
        Next


        For Each address In GetNullAddressSold()
            For i As Integer = 0 To dtsold.Rows.Count - 1

                Dim StreetAddress As String = CStr(dtsold.Rows(i)("FullStreetAddress"))
                Dim City As String = CStr(dtsold.Rows(i)("City"))
                Dim State As String = CStr(dtsold.Rows(i)("State"))
                Dim Zip As String = CStr(dtsold.Rows(i)("ZipCode"))
                SearchAddress = GetAddress(StreetAddress, City, State, Zip)
                dtsold.Rows(i).Item("Latitude") = CStr(SearchAddress.Latitude)
                dtsold.Rows(i).Item("Longitude") = CStr(SearchAddress.Longitude)
            Next
            ProgressBar3.PerformStep()
        Next


    End Function

look for the carriage return character

$
0
0
Hello,

I'm having problem to read the data from a device i.e. Watson GPS.
It started with letter 'I' and ended with CR (carriage return).

I was suggested to 'look for the carriage return character, and then parse the received data frame by the spacebar character'.

i need to know how can i read the carriage return (vbCr) from the incoming data?
here is currently part of my existing code:
Code:

Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
        ReceivedText(SerialPort1.ReadExisting()) 'Automatically called every time a data is received at the serialPort

    End Sub
    Private Sub ReceivedText(ByVal [text] As String)
        'compares the ID of the creating Thread to the ID of the calling Thread
        If Me.rtbReceived.InvokeRequired Then
            Dim x As New SetTextCallback(AddressOf ReceivedText)
            Me.Invoke(x, New Object() {(text)})

        Else
            Me.rtbReceived.Text &= text
                Me.RichTextBox1.Text = text + vbNewLine + RichTextBox1.Text 'same as above line actually

                Me.RichTextBox2.Text = TimeOfDay.ToLongTimeString + " : " + [text] + vbNewLine + RichTextBox2.Text

                Dim i As Integer
                Dim character As String
                character = split_char_label.Text
                Dim split_data() As String = Split([text], character)
                Dim no_of_data = split_data.GetLength(0)
                no_of_data_label.Text = no_of_data

                For i = 0 To i = i + 1

                    If data_no_label_1.Text = "" Then
                        TextBox1.Text = ""
                    Else Try
                            Int32.TryParse(data_no_label_1.Text, i) 'convert i=string to i=integer
                            TextBox1.Text = split_data(i)
                        Catch ex As Exception
                        End Try
                    End If

                    If data_no_label_2.Text = "" Then
                        TextBox2.Text = ""
                    Else Try
                            Int32.TryParse(data_no_label_2.Text, i)
                            TextBox2.Text = split_data(i)
                        Catch ex As Exception
                        End Try
                    End If

                    If data_no_label_3.Text = "" Then
                        TextBox3.Text = ""
                    Else Try
                            Int32.TryParse(data_no_label_3.Text, i)
                            TextBox3.Text = split_data(i)
                        Catch ex As Exception
                        End Try
                    End If
                Next

                Try
                    'SIMPLE SPLIT DATA CODE
                    Dim s As String
                    s = RichTextBox1.Text

                    Dim somestring() As String
                    'split based on comma
                    somestring = s.Split(New Char() {","c})

                    TextBox4.Text = somestring(0)
                    TextBox5.Text = somestring(1)
                    TextBox6.Text = somestring(2)
                    TextBox7.Text = somestring(3)
                    TextBox8.Text = somestring(4)
                    TextBox9.Text = somestring(5)
                Catch e As Exception
                End Try


        End If

        Button2.Text = TextBox1.Text
        'GaugeControl2.SetPointerValue("Scale1", "Pointer1", Val(TextBox1.Text))

        Button1.Text = TextBox2.Text
        'GaugeControl1.SetPointerValue("Scale1", "Pointer1", Val(TextBox2.Text))

        Button3.Text = TextBox3.Text
        'GaugeControl3.SetPointerValue("Scale1", "Pointer1", Val(TextBox3.Text))


    End Sub

my serial comm is working fine only that i could not get stable data. the data i receive is like in the video.
Name:  6.png
Views: 110
Size:  7.4 KB
Attached Images
 

How can I set an event using the data from a SQL database

$
0
0
Hi all
I have written simple programs that show in DataGridView some info. The most important info is the expiration date , which I manage to color it read when the expiration date is near(like 5 days). The person responsible has an email in the database. I use a SQL database. What is the code to send email only to the persons that their products are near the expiration date? If I call the function send_mail() in the code that colors the line red it sends infinite mails to 1 person. This is my code:

Private Sub dgvExcel_CellFormatting(sender As Object, e As DataGridViewCellFormattingEventArgs) Handles DataGridView1.CellFormatting

If CDate(DataGridView1.Rows(e.RowIndex).Cells(DataGridView1.Columns(5).Index).Value) <= Date.Now Then
e.CellStyle.BackColor = Color.Red
'send_mail()
End If

If CDate(DataGridView1.Rows(e.RowIndex).Cells(DataGridView1.Columns(4).Index).Value) <= Date.Now Then
e.CellStyle.BackColor = Color.White
e.CellStyle.ForeColor = Color.Black
End If


End Sub

VS 2013 Vb net permutation list only between odds...

$
0
0
Code:

using System;
using System.Collections.Generic;

namespace PermutationsOfInteger
{
    class Program
    {
        static void Main(string[] args)
        {
            PrintResult(
                Permute(new int[] { 1,2,3 })
            );
        }

        static IList<IList<int>> Permute(int[] nums)
        {
            var list = new List<IList<int>>();
            return DoPermute(nums, 0, nums.Length - 1, list);
        }

        static IList<IList<int>> DoPermute(int[] nums, int start, int end, IList<IList<int>> list)
        {
            if (start == end)
            {
                // We have one of our possible n! solutions,
                // add it to the list.
                list.Add(new List<int>(nums));
            }
            else
            {
                for (var i = start; i <= end; i++)
                {
                    Swap(ref nums[start], ref nums[i]);
                    DoPermute(nums, start + 1, end, list);
                    Swap(ref nums[start], ref nums[i]);
                }
            }

            return list;
        }

        static void Swap(ref int a, ref int b)
        {
            var temp = a;
            a = b;
            b = temp;
        }

        static void PrintResult(IList<IList<int>> lists)
        {
            Console.WriteLine("[");
            foreach (var list in lists)
            {
                Console.WriteLine($"    [{string.Join(',', list)}]");
            }
            Console.WriteLine("]");
        }
    }
}

Here is good code for permutation from the link: https://www.chadgolden.com/blog/find...ray-in-c-sharp

Question: How can I change this so it can do permutation only
- even with even
- odd with odds

for example:

Here is list ALL pemutatitions for {"AAA", "BBB", "CCC", "DDD", "EEE"}


AAA+BBB+CCC+DDD+EEE
AAA+BBB+CCC+EEE+DDD
AAA+BBB+DDD+CCC+EEE
AAA+BBB+DDD+EEE+CCC
AAA+BBB+EEE+DDD+CCC
AAA+BBB+EEE+CCC+DDD
AAA+CCC+BBB+DDD+EEE
AAA+CCC+BBB+EEE+DDD
AAA+CCC+DDD+BBB+EEE
AAA+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AAA+CCC
EEE+DDD+AAA+BBB+CCC
EEE+DDD+AAA+CCC+BBB
EEE+AAA+CCC+DDD+BBB
EEE+AAA+CCC+BBB+DDD
EEE+AAA+DDD+CCC+BBB
EEE+AAA+DDD+BBB+CCC
EEE+AAA+BBB+DDD+CCC
EEE+AAA+BBB+CCC+DDD


Rule should be:

AAA can be permutated with CCC and EEE only
BBB can be permutatated with DDD only..
CCC can be permutated with AAA and EEE only....

Thanks

Asking for eyes on code, did I close out processes correctly

$
0
0
I was writing some code to start and stop a VPN connection for a Visual Basic application that I was writing. I am normally a straight VB/data guy and I don't do much with process and threading. Almost all the examples I found online were written for C or C++. Did my best to convert the code over to VB.

I watched processes on the test workstation and things appear to be closing out but I am not convinced I wrote everything correctly or according to Best Practices. Would appreciate any time and advice on the code below. Did I terminate processes correctly? Follow norms? etc?

I put bogus information is VPN fields for obvious reasons.

Oh, one annoying thing. When I click to disconnect VPN, my first line goes in OK. A message from the process goes in and says Disconnecting...
I will not display disconnected. When I try to add this line
Code:

            txtMsg.AppendText(String.Concat("-- ", "Disconnected", Environment.NewLine))
at the bottom of the sub, the line appears before "Disconnecting" instead of the bottom. Assuming it hits the command before the process officially ends. Is pause necessary here and something else? I kept reading that "waitforexit" shouldn't be used for the realtime writing of messages and when invoked; the message won't got to the form. Wondering what another possibility might be to get that last line?

Code from Form:
Code:

    Private Sub ConnNE_Click(sender As Object, e As EventArgs) Handles ConnNE.Click
        Dim p As Process = New Process
        Dim pi As ProcessStartInfo = New ProcessStartInfo()

        txtMsg.Clear()

        With pi
            .WorkingDirectory = "c:\Program Files (x86)\SonicWALL\SSL-VPN\NetExtender\"
            .FileName = "cmd.exe"
            .Arguments = "/c NECLI.exe connect -s myserver.com -d myDomain.local -u myID -p myPassword"
            .WindowStyle = ProcessWindowStyle.Normal
            .CreateNoWindow = True
            .UseShellExecute = False
            .RedirectStandardOutput = True
            .RedirectStandardError = True
        End With

        p.StartInfo = pi

        Try
            AddHandler p.OutputDataReceived, AddressOf consoleOutputHandler
            AddHandler p.ErrorDataReceived, AddressOf consoleErrorHandler

            txtMsg.AppendText(String.Concat("-- ", "Initializing Connection", Environment.NewLine))

            p.Start()
            p.BeginOutputReadLine()
            'p.WaitForExit()
            p.Close()

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

    End Sub

    Private Delegate Sub consoleOutputDelegate(ByVal outputString As String)

    Private Sub consoleOutput(ByVal outputString As String)
 
        If Me.InvokeRequired Then
            Dim del As New consoleOutputDelegate(AddressOf consoleOutput)
            Dim args As Object() = {outputString}
            Me.Invoke(del, args)
        Else
            txtMsg.AppendText(String.Concat("-- ", outputString, Environment.NewLine))
            'txtMsg.Refresh()
        End If
    End Sub

    Sub consoleOutputHandler(ByVal sendingProcess As Object, ByVal outLine As DataReceivedEventArgs)
        If Not String.IsNullOrEmpty(outLine.Data) Then
            consoleOutput(outLine.Data)
        End If
    End Sub

    Private Delegate Sub consoleErrorDelegate(ByVal errorString As String)
 
  Private Sub consoleError(ByVal errorString As String)
        If Me.InvokeRequired Then
            Dim del As New consoleErrorDelegate(AddressOf consoleError)
            Dim args As Object() = {errorString}
            Me.Invoke(del, args)
        Else
                        txtMsg.AppendText(String.Concat("Error: ", errorString, Environment.NewLine))
        End If
    End Sub
 
    Private Sub consoleErrorHandler(ByVal sendingProcess As Object, ByVal errLine As DataReceivedEventArgs)
        If Not String.IsNullOrEmpty(errLine.Data) Then
                        consoleError(errLine.Data)
        End If
    End Sub

    Private Sub DisConnNE_Click(sender As Object, e As EventArgs) Handles DisConnNE.Click
        Dim p As Process = New Process
        Dim pi As ProcessStartInfo = New ProcessStartInfo()

        With pi
            .WorkingDirectory = "c:\Program Files (x86)\SonicWALL\SSL-VPN\NetExtender\"
            .FileName = "cmd.exe"
            .Arguments = "/c NECLI.exe disconnect"
            .WindowStyle = ProcessWindowStyle.Normal
            .CreateNoWindow = True
            .UseShellExecute = False
            .RedirectStandardOutput = True
            .RedirectStandardError = True
        End With

        p.StartInfo = pi

        Try
            AddHandler p.OutputDataReceived, AddressOf consoleOutputHandler
            AddHandler p.ErrorDataReceived, AddressOf consoleErrorHandler

            txtMsg.AppendText(String.Concat("-- ", "Initializing Disconnect", Environment.NewLine))
            'txtMsg.Refresh()

            p.Start()
            p.BeginOutputReadLine()
            'p.WaitForExit()
            p.Close()

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

    End Sub

Save All Data in Datagridview to Access DB

$
0
0
Hello, I am trying to save all data that are in a datagridview to my Access DB. The data are added via code:

Code:

Me.dgvHistory.Rows.Add(Environment.UserName.ToLower, DateAndTime.Now, "Uploaded Raw Data")
I am not sure how to use a datatable in this scenario because the data that will be put into the datagridview will come from 3 separate forms. Basically everytime a user clicks on some buttons, the action done will be saved into the datagridview.

Any suggestions?

Catching an event in a serice

$
0
0
I am trying to write a (simple) service that does something when the computer awakens. To make sure that things are heading in the right direction, I started by first writing a simple service [basically, it just writes a string to the event log]. That worked!

Then, I tried to modify the code so that it would write a string to the event log each time a mouse button was clicked within the past 10 seconds. I figured that to detect the mouse click, I should look for the event as this would be, programmatically, quite similar to the desired goal. Sadly, this did not work.

Following is the code - please tell me what to add to make it work, i.e., please provide the code that should be in the MyTickHandler function. Thanks!

Code:

Imports System.Diagnostics 
Imports System.Timers 
 
Public Class MyTestService 
    Private Timer1 As New Timer With {.Interval = 1000} 
 
    Public Sub New() 
        MyBase.New() 
        InitializeComponent() 
 
        ' Set up event log 
        Me.EventLog1 = New System.Diagnostics.EventLog 
        EventLog1.Source = "MyTestSource" 
        EventLog1.Log = "MyTestNewLog" 
 
        If Not System.Diagnostics.EventLog.SourceExists(EventLog1.Source) Then 
            System.Diagnostics.EventLog.CreateEventSource(EventLog1.Source, EventLog1.Log) 
        End If

        AddHandler Timer1.Elapsed, New ElapsedEventHandler(AddressOf MyTickHandler) 
        Timer1.Start() 
    End Sub 
 
    Protected Overrides Sub OnStart(ByVal args() As String) 
        EventLog1.WriteEntry("In OnStart") 
    End Sub 
 
    Protected Overrides Sub OnStop() 
        EventLog1.WriteEntry("In OnStop.") 
    End Sub 
 
    Sub MyTickHandler(ByVal sender As Object, ByVal e As EventArgs) 
        ' if mouse is clicked, then call: EventLog1.WriteEntry("MouseClick") 
    End Sub 
End Class

Viewing all 27474 articles
Browse latest View live


Latest Images

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