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

Modal Forms - Passing List(Of) across

$
0
0
Hi again,

I am somewhat familiar with passing objects/variables across to a modal form. You set the public property of the form you are showing and send across the variable/list/object when creating the instance of the form:

Code:

modalForm = new subForm(list)
modalForm.ShowDialog()

And pick it up in the Private Sub New() of the modal form and set it to the public property.

I pass across my list, and in the form I make a few additions to the list. When the modal form is closed and I count my list, I don't have the additions that were made in the modal form. I'm obviously not grasping this but I though I was passing across the list so I could use it in the modal form. What seems to be happening is the list is copied into the opening form, the additions are made, and all this is discarded when the form closes again.

I have fixed this by:

Code:

    Public ReadOnly Property Jobs As List(Of Site)
        Get
            Return list

        End Get
    End Property

I can pick up the list from the form that called the modal form by:

Code:


list = modalform.Jobs

Is there any way just to send over my list to the modal form and allow the modal form to change it and keep the changes back in the parent form? Or am I way off here?

Thanks again for any help. This forum is very helpful!

[RESOLVED] adding zero if byte is less than 10

$
0
0
Hi

I am converting a byte array to hex, problem is I lose the zero if the hex value is less than 10. I've tried googling the problem and cant seem to find a solution for my case.

If you can spot something I've missed I'd appreciate it

Code:

  1. Function BinaryToHex_Curve(ByRef binaryData As Byte()) As String
  2.         Dim hexValue As String = ""
  3.         Dim I32 As Int32
  4.         For I32 = 4 To binaryData.Length - 1
  5.             hexValue = hexValue + (String.Format("{0}", binaryData(I32).ToString("X")))
  6.         Next
  7.         Return hexValue
  8.     End Function

VS 2015 Sorting an array of bytes

$
0
0
Hi all

Well just after some advice
I have an array of bytes around 120 bytes long. And every 4 bytes there is a number stored in a float.

What would the most efficient way of grabbing each of the 4 bytes and storing them into a separate string.

Right now I've tried a for loop getting for bytes, returning a value and changing what four bytes i want. And so on.

Any other ideas.

Cheers

Stored Procedure/TableAdapter and Failed to enable contraints

$
0
0
I have been struggling for several days now trying to figure out why I am getting the failed to enable constraints, one or more rows contain values violating non-null, unique, or foreign-key constraints when running my code. I have a stored procedure in sql server, part of it below:

Code:

                  BEGIN
                        CREATE TABLE #t
                        (
                                    empl_id                          VARCHAR(20),
                                    empl_cctr_id                  INTEGER,
                                    yr                                  DECIMAL(4,0),
                                    rhrs                                  DECIMAL(8,2),
                                    othrs                                  DECIMAL(8,2),
                                    x10210                          DECIMAL(8,2),
                                    x10220                          DECIMAL(8,2),
                                    x103xx                          DECIMAL(8,2),
                                    x10303                              DECIMAL(8,2),
                                    x104xx                          DECIMAL(8,2),
                                    x105xx                          DECIMAL(8,2),
                                    x106xx                          DECIMAL(8,2),
                                    x109xx                          DECIMAL(8,2),
                                    x10901                          DECIMAL(8,2),
                                    other                                  DECIMAL(8,2),
                                    nhrs                                  DECIMAL(8,2),
                                    tothrs                          DECIMAL(8,2)
                        )

                        INSERT INTO #t (empl_id, empl_cctr_id, yr, rhrs, othrs, x10210, x10220, x103xx, x10303, x104xx, x105xx, x106xx, x109xx, x10901, other, nhrs, tothrs)
                        EXEC getSMETDetailsAll @yr, 0, 55, @mgr

                        SELECT
                                e.empl_last_nm + ', ' + e.empl_first_nm + ' ' + e.empl_middle_init                        AS Employee,
                                e.empl_id                                                                                                                        AS [Empl ID],
                                e.empl_myid                                                                                                                AS MyID,
                                ISNULL(s.Scheduled,0)                                                                                                AS Scheduled,
                                ISNULL(n.nph_vac_used,0)                                                                                                AS [PTO-Used],
                                ISNULL(w.wsum_nph10220,0)                                                                                        AS Holiday,
                                ISNULL(w.wsum_nph109xx,0)                                                                                        AS [109xx],
                                ISNULL(w.wsum_other,0)                                                                                                AS Misc,
                                ISNULL(s.Scheduled - (n.nph_vac_used + w.wsum_nph10220 + w.wsum_other +
                                    w.wsum_nph109xx + n.nph_fmla + n.nph_mil + n.nph_disability),0)                        AS Net,
                                ISNULL(n.nph_fmla,0)                                                                                                AS FMLA,
                                ISNULL(n.nph_mil,0)                                                                                                        AS Military,
                                ISNULL(n.nph_disability,0)                                                                                        AS Disability,
                                ISNULL(convert(decimal(8,2),((t.rhrs + t.othrs)  / (s.pp_cnt * 40)) * 100),0)        AS [Productivity Index]
                        FROM
                                TEMSEMPL e
                                LEFT JOIN TEMSNPH n ON e.empl_id = n.nph_empl_id
                                LEFT JOIN TEMSWSUM w on e.empl_id = w.wsum_empl_id
                                LEFT JOIN
                                    (SELECT hist_empl_id, hist_yr, max(convert(integer,hist_pp)) - min(convert(integer,hist_pp))  + 1 as pp_cnt,
                                                  (max(convert(integer,hist_pp)) - min(convert(integer,hist_pp))  + 1) * 40 AS Scheduled
                                    FROM          TEMSHIST
                                    WHERE          hist_yr = @yr
                                    GROUP BY hist_empl_id, hist_yr) s
                                ON s.hist_empl_id = e.empl_id
                                LEFT JOIN
                                    (SELECT * from #t) t
                                ON t.empl_id = e.empl_id
                        WHERE
                                (e.empl_stat_id IN (1, 2, 3, 4, 6, 8)) AND
                                n.nph_payyr = @yr and e.empl_mgr_id = @mgr and e.empl_id is not null
                               
                  DROP TABLE #t
          END

In my application I perform get data on the stored procedure:
Code:

                Dim absdt As New EMS_DS.getABS4BARDataTable
                Dim absta As New EMS_DSTableAdapters.getABS4BARTableAdapter
                absdt = absta.GetData(BaseYr, managerLUE.EditValue)

On the getdata line i get the failed to enable constraints. There shouldnt be any constraints. I removed the primary key that the data designer created when I added the table adapter (something i saw when I searched for a solution prior to posting). I tried turning off enforce constraints, but that didnt work. Ive tried changing the statement to left join, inner join, etc.

If i execute the stored procedure in sql server management studio, it works just fine. No data is missing.

Please help me figure this out.

VS 2012 dll question

$
0
0
Hi, I am mostly a vb6 programmer. I want to learn vb.net

I have explored some in vb.net, right now I am interested how to create a dll and ocx and how use it on the application.

Capturing Pictures from Web Cam

$
0
0
hi, i want to capture image and save it every 2 seconds through my webcam any help pls

Scroll horizontal and vertical vb form

$
0
0
Hi Guys,

Id like to ask how should i make the Hscroll bar and vscrollbar usable? When i adjust the form size. I should be able to scroll left,right and up and down in the form to see all my data inside the form.

Im currently in still search on how to do it. Hoping for your kind help :(

Regards,
Newbie....

Request was aborted? (SSL/TLS)

$
0
0
So i have been working on a program on and off for the last month or so and last night i was working on said program no problem, everything worked and loaded fine.

Today i booted up and just ran the program and i now get this error
Quote:

Additional information: The request was aborted: Could not create SSL/TLS secure channel.
I am using the HTMLAgility-Pack. I have a strong feeling that the website that i am getting the information from has changed something to block me getting information this way? I say this as i loaded up a different program that i have made that pretty much does the same thing and i get the error there as well but when i try to scrape some data from a different website it works.

Is there any way to fix this?

Huge whitespace in Panel control

$
0
0
Hi guys,

I am having a problem with a panel control. When in the designer, everything looks and is setup correct. But when I run the program, a huge whitespace is present in the panel. I have had problems in the past where the designer would do this for no apparent reason, and you could not correct it.

The first SS is the way it looks in the designer, which is correct, then when you run the program, the huge whitespace is there.

Any suggestions? (SS attached)
Attached Images
  

VS 2010 Multiline Textbox AutoComplete

$
0
0
Why autocomplete not working on multiline textbox, how can i make to work? i tried with this but not helpful
AutoCompleteMode = Append
AutoCompleteSource = CustomSource
Code:

        Dim MySource As New AutoCompleteStringCollection()
        MySource.AddRange(New String() _
                            { _
                                "January" & vbNewLine & "this", _
                                "February", _
                                "March", _
                                "April", _
                                "May", _
                                "June", _
                                "July", _
                                "August", _
                                "September", _
                                "October", _
                                "November", _
                                "December" _
                            })
        TextBox1.AutoCompleteCustomSource = MySource

VS 2015 Logic Help Needed - I'm stumped (I say that too often)

$
0
0
Hello All,

Here is the jist of things. I've been testing some logic for speed, accuracy and a few other things. We've moved from small and medium testing to real world environment.
Fly meet ointment.

We need to gather directory and file listing only for this step. We just need to hold all the information in order to process it in the next step.

Its something like this.
Step 1. Gather Directory Listing
Step 2. Compile File and Directory Attributes
Step 2a. Add Directory listings from step 1 and attributes gathered in step 2 and insert them into a SQLite Database. This step runs at the same time as the attributes are being extracted.

Step 1 and Step 2 need to be distinct in order to facilitate other analysis.


When testing with 1,000,000 Files and/or directories - memory usage was at less than 500MB.
Moving up to 5,000,000 files and/or directories - memory usage was slightly less than the expected 5 times the first test or just under 2.3GB.

We allocated 512GB of RAM on a production server to test the limits and we're not even close to an acceptable range.

When testing with 100,000,000 files and/or directories we throw an out of memory exception. We need to scale that up to 600 million records before it can be considered above consumer quality.

Here is the code I use and the reasons for using it.
I tried to use a command prompt and send all the data to a Txt file. That brought up lots of issues. I was unable to catch any errors and they ended up inside the text file. I was unable to capture progress and update the main GUI, that resulted in very long delays without relaying any information to the user.
It was significantly slower the using RAM.

Can anyone offer an alternate solution? At this point we don't care if we have to add the path and files to a table in the SQLite DB. I just can't figure out how to broaden the scope of the logic below to allow me to capture 50K or 60K files at a clip and just do a bulk insert.


Code:

' This stack stores the directories to process
            Dim stack As New Stack(Of String)

            ' Add the initial directory
            stack.Push(FoldertoProcess)

            ' Continue processing for each stacked directory
            Do While (stack.Count > 0)
                ' Get top directory string
                Dim dir As String = stack.Pop

                Try

                    ' Add all immediate file paths
                    result.AddRange(Directory.GetFiles(dir, "*.*"))
                    DisplayCounter = result.Count()
                    If DisplayCounter > waitcounter Then
                        WorkerArgs.FilesFound(BGWNum) = DisplayCounter
                        worker.ReportProgress(-4, BGWNum)
                        waitcounter = waitcounter + 25000
                    End If

                    ' Loop through all subdirectories and add them to the stack
                    Dim directoryName As String
                    For Each directoryName In Directory.GetDirectories(dir)
                        stack.Push(directoryName)
                    Next

                Catch UA As UnauthorizedAccessException
                    'ignore
                Catch DNF As DirectoryNotFoundException
                    'ignore
                Catch PTL As Path TooLong Exception
                    'ignore
                Catch EPNF As EntryPointNotFoundException
                    'ignore
                Catch ex As Exception

                    worker.CancelAsync()
                    e.Cancel = True
                    e.Result = True
                    BGWCancelMessage = "(1) Thread Cancel on Directory read" + vbCrLf + ex.Message

                End Try

            Loop

VS 2015 If not all Text Printed then start new page

$
0
0
Hello! I am developing an application and I want to utilize the print feature on it. I have got the printing down, full page, word wrap and stuff. Anyways, I wanna have it print to a new page if all words have not printed properly. Anyway? Like it detect it with New Rectangle for the word wrap? VB.NET, Thanks too!

vb mapping

$
0
0
Hello I'm need to vb I normally program plc I have just started using vb for touchscreens a i'm trying to
make graphics move at a good rate so i'm try to map number like in Arduino programing * val = map(val, 0, 1023, 0, 255);
please any suggestions
thanks

VB Code but dont know how to activate in excell

$
0
0
Hi
I found this code online for deleting text in a cell that is red. But it did not say how to run it. Anyone can help?

Sub ForEachCharacterTextColor()
Dim wbk As Workbook
Dim i As Integer
Set wbk = ThisWorkbook
Set ws = wbk.Sheets(1)

Dim cell As Range

Cells.Select
Selection.NumberFormat = "@"
Range("A1").Select

On Error GoTo MyExitSub

With ws
For Each cell In ws.Range("A1:E2000").Cells
'cell.Value = "'" & cell.Value
For i = 1 To Len(cell)
If cell.Characters(i, 1).Font.Color = RGB(0, 0, 0) Then
If Len(cell) > 0 Then
cell.Characters(i, 1).Delete
End If
If Len(cell) > 0 Then
i = i - 1
End If
End If
Next i
Next cell
End With


MyExitSub:
If Err.Number > 0 Then
MsgBox "Some of your cells are numbers formatted as text. You need to convert them to text completely."
End
End If
End Sub

VS 2015 Need Help- print a report all displaying in Datagridview currently-After Filtering

$
0
0
Dear Friends,
I am not expert in Programming. But I am developing small program for internal purpose.
I made VB.net application with sql database.
In main Form I am filtering the database records based on some criteria.
After filtering in the datagridview I am seeing final matching records.
I want to Print those rows into VB inbuilt Report viewer.
I am stuck here... Please help ....

Thank you...

Victor

simple math problem

$
0
0
need help to solve simple arithmetic problem
integer var: s = 1 to 7, a = 1 to 5, b = 1 to 9
I want to found solution for equation

s*2 = a + b
when a< s and b< s
I have zero result with this code

Sub Main()
For s As Integer = 1 To 7
For a As Integer = 1 To 5
If a < s Then
a = a
End If
For b As Integer = 1 To 9
If b < s Then
b = b
End If
If s * 2 = a + b Then
Console.Write("number is:", s, a, b)
Console.ReadLine()
End If

Next
Next
Next
Console.ReadLine()
End Sub

I try different loops no result. Please some body push to right direction
thanks

List of to Datagridview bug?

$
0
0
Hi.
I'm binding a class that is of a list of T in a datagridview datasource.
When I do that the rows will show fine but when i go to get the cell value it is empty.

What seems to work is if I use a IEnumerable to bind the list to datatable that will bind to the datagridview.

Is this a bug?
If it is not then why i do not get data with the simple list bind?
If it is then why do I get the rows OK with empty value.

This is actually not a issue now because, as I've said, i bind it with a datatable but if they do not support a direct list bind, why do the let it slide when coding?

Thanks.

Is it possible to obfuscate VB.NET code without it easily being deobfuscated?

$
0
0
I'm trying to protect my VB.NET app. I've been advised to obfuscate the code. But what good does this do if you can deobfuscate the code easily?

https://www.youtube.com/watch?v=eK3D-qgLY80&t=43s

I'm aware that protecting code 100 percent is impossible. But it seems to me that an obfuscator that can easily be defeated is pretty much useless. Does an obfuscator exist that can't easily be defeated?

VS 2017 Attempting to Write Data from DGV to Dbase IV DBF File

$
0
0
Seems like database are my nemesis. I always struggle with them. There is wildly contradicting advice on the web. Maybe I am not understanding it

I have a data set with several tables. There is a DGV bound to one on the tables. This data in the DGV is bound to the table with a binding source. I am trying to write all the data in the bound DGV to a Dbase DBF file.

I have tried various options. The problem seems to be with the SELECT INTO command.

Any assistance appreciated.

Code:

        Dim sFilePath As String = "D:\Temp\Namdeb Configuration Data\Export\" & "equip.dbf"
        Dim sFolder As String = "D:\Temp\Namdeb Configuration Data\Export\"
        Dim sDBFFileNameNoExtension As String = Path.GetFileNameWithoutExtension(sFilePath)


        Dim cmdString As String = TryCast("SELECT * INTO " & sDBFFileNameNoExtension & " From " & DGVScadaEquipmentGeneration.DataSource, String)

        Dim cnn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=dBase IV;Data Source='" & sFolder & "'")

        Try
            cnn.Open()

            Dim da As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter()
            Dim cmd As New OleDb.OleDbCommand(cmdString, cnn)

            da.SelectCommand = cmd

            cmd.ExecuteNonQuery()

            da.Dispose()
            cnn.Close()

        Catch ex As Exception
            ' Handle the exception.
            MessageBox.Show(ex.Message, Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            '    'Nothing
      End Try

Tried this as well

Code:

Dim cmdString As String = TryCast("SELECT * INTO " & sDBFFileNameNoExtension & " From " & TbEquipmentScadaBindingSource.DataSource, String)

How to include image or sound in VB 2010

$
0
0
Hi everyone,

I just started programming for about 3 months ago and only knew the basic command of visual basic. However, recently I just received a project to make a simple classical game like "Space invader". So I was wondering if it's possible to put a random image from my computer as the game background as well as including music? If yes, can you please provide the example code for it? Note that, I must execute the game in console application rather than window application and as far as i knows the commands seem to be a little different even though both are in visual basic categories. I will be very appreciate,if you can provide some other game related code references too as I'm having a hard time to salvage useful information from googling.
Viewing all 26522 articles
Browse latest View live


Latest Images