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

VS 2010 Filter DataGridView1 with TextBox.Text

$
0
0
Dear friends,

good Day.

I use DataGridView1 to display list of employees and I need to filter based on TextBox.Text.
But i tried in few but not get filter when TextBox.Text changes.

Code:

Imports System.Data.OleDb
Imports System.IO


Public Class Form1
    'Global Declaration for Class frmSM
    Dim AddMode As Boolean
    Dim Ctrl As Integer
    Dim myConn As New OleDbConnection
    Dim myCmd As New OleDbCommand
    Dim myDA As New OleDbDataAdapter
    Dim myDR As OleDbDataReader
    Dim strSQL As String

    Private Property DBPath As String

    Function IsConnected() As Boolean
        Try
            'Checks first if already connected to database,if connected, it will be disconnected.
            If myConn.State = ConnectionState.Open Then myConn.Close()
            myConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\dbLab.mdb;"
            myConn.Open()
            IsConnected = True
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Function
    Private Sub txtSearchBox_TextChanged(ByVal Sender As System.Object, ByVal e As System.EventArgs) Handles txtSearchBox.TextChanged

        myDA = New OleDbDataAdapter("Select * From tblStudentMaster", myConn)
        Dim DtSet As New DataSet
        myDA.Fill(DtSet)
        Dim bs As New BindingSource
        bs.DataSource = DtSet
        bs.Filter = " SM_ID LIKE'" & txtSearchBox.Text & "*' Or SM_FName LIKE '" & txtSearchBox.Text & "*' Or SM_LName LIKE '" & txtSearchBox.Text & "*' Or SM_MName LIKE '" & txtSearchBox.Text & "*'"
        DataGridView1.DataSource = DtSet.Tables(0)
        myConn.Close()
        ''  Dim row As DataGridViewRow = DataGridView1.Rows(0)
        ''  row.Height = 20

    End Sub

Could anyone please help me to get this done.

with Thanks
ebincharles

VS 2013 [RESOLVED] Parallel.ForEach Project

$
0
0
Hello All,

I have a query about the code below.

I have around 4700 CSV files (each around 50 kB) containing data rows (composed of many columns per each row).

I have a list of given cells (around 500 cells), I want to use Parallel.ForEach to read simultaneously as many files as possible and start searching each row in each file for one of the given cells I have.

The point here, that once I find one cell in a file, I should remove that cell from my list because I already found what I want in one of the CSV files i.e. no need to keep searching for the same cell over an over in other files.

The code runs perfectly if used MaxDegreeOfParallelism = 1 which basically no parallelism at all! or used normal Foreach.

Otherwise, it keep giving me error .. "Value cannot be null. Parameter name: value" .. any help?





Code:


dirpath = "C:\CSVLogs"

Dim files() As FileInfo = New DirectoryInfo(dirpath).GetFiles

        Try
            Dim ParallelOpts As New ParallelOptions
            With ParallelOpts
                .MaxDegreeOfParallelism = 10
                .CancellationToken = ct.Token
            End With

            Dim CAPs As New ConcurrentBag(Of String)
            For Each CAP As String In lstbx.Items
                CAPs.Add(CAP)
            Next

            Dim lines As New ConcurrentBag(Of String)

            pbar.Invoke(Sub()
                            pbar.Value = 0
                            pbar.Maximum = files.Length
                        End Sub)


            Parallel.ForEach(files, ParallelOpts, Sub(file As FileInfo)
                                                      Try
                                                          Dim rows As ConcurrentBag(Of String) = ReadFile(file.FullName)
                                                          Dim i As Integer = 0
                                                          While i <= CAPs.Count - 1
                                                              Dim foundCAP As Boolean = False
                                                              For Each row As String In rows
                                                                  If row.Contains(CAPs(i)) Then ', StringComparer.OrdinalIgnoreCase) Then
                                                                      Try
                                                                          lines.Add(row)
                                                                          CAPs.TryTake(CAPs(i))
                                                                          foundCAP = True
                                                                          Exit For
                                                                      Catch ex As Exception
                                                                          MessageBox.Show(ex.Message)
                                                                      End Try
                                                                  End If
                                                              Next
                                                              If Not foundCAP Then i += 1
                                                          End While
                                                      Catch ex As Exception
                                                          MessageBox.Show(ex.Message)
                                                      End Try
                                                      pbar.Invoke(Sub() pbar.PerformStep())
                                                  End Sub)

            If lines.Count > 0 Then Me.Invoke(Sub() ExportToCSVSub(lines))
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

VS 2013 [RESOLVED] hide application icon from taskbar

$
0
0
i made application to show my internet bandwidth
right now i would like away to hide the icon from the taskbar and let only the text

Name:  1.JPG
Views: 81
Size:  14.9 KB
Attached Images
 

VS 2015 , [ASK] Photoviewer

$
0
0
Hello Guys , sorry to bother you again.. i'm here as a newbie want to ask you all how to solve my problem..
so here's my problem..

i've asked you about the photoviewer topic before and i want to show you how is my progress so far
and here's the code

Code:

Public Class Form1


    Private Sub ExitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ExitToolStripMenuItem.Click
        End

    End Sub

    Private ImageFiles As List(Of String)
    Private ImageIndex As Integer


    Private Sub GetImage()
        Try
            Picture1.Image = Image.FromFile(ImageFiles(ImageIndex))
        Catch
            Dim imgpath As String = ImageFiles(ImageIndex)
            MessageBox.Show("error reading image from file" & IO.Path.GetFileName(imgpath))

        Catch ex As Exception

        End Try
    End Sub
    Private Sub OpenImageToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles OpenImageToolStripMenuItem.Click
        Using ofd As New OpenFileDialog With {.Filter = "image files|*.png;*.jpg;*.jpeg;*.gif;*.bmp;*.tif;*.tiff;|All Files|*.*"}
            If ofd.ShowDialog = DialogResult.OK Then
                Dim imagefolder As String = IO.Path.GetDirectoryName(ofd.FileName)
                ImageFiles = New List(Of String)
                Dim extensions As String() = {"*.png", "*.jpg", "*.jpeg", "*.gif", "*.bmp", "*.tif", "*.tiff"}
                For Each ext As String In extensions
                    ImageFiles.AddRange(IO.Directory.GetFiles(imagefolder, ext.ToLower, IO.SearchOption.TopDirectoryOnly))
                Next
                ImageFiles.Sort()
                ImageIndex = ImageFiles.IndexOf(ofd.FileName)
                GetImage()

            End If
            directorybox.Text = ofd.FileName
        End Using
    End Sub

    Private Sub nextbutton_Click(sender As Object, e As EventArgs) Handles nextbutton.Click
        If ImageFiles.Count > 0 Then
            ImageIndex = (ImageFiles.Count + ImageIndex - 1) Mod ImageFiles.Count
            GetImage()



        End If


    End Sub


    Private Sub previousbutton_Click(sender As Object, e As EventArgs) Handles previousbutton.Click
        If ImageFiles.Count > 0 Then
            ImageIndex = (ImageIndex + 1) Mod ImageFiles.Count
            GetImage()
        End If
    End Sub
End Class

and as you can see there's a getimage() sub and it's connected to the next and previous button and also the picture box

and there's a open file dialog sub it's connected to the picture box and also connected to the textbox which i called it "directorybox.text"

but here's the problem guys.. i tried to open an image from
open file dialog sub which it use the using.. end using statement , and because i put the "directorybox.text = ofd.filename" on the openfiledialog sub and it's also on the using ofd statement , and so the directorybox.text update the file path as equal to the openfiledialog path ,

but when i use the next button.. "yeah the image changed , but the directorybox.text file path doesn't change anything.. so it follow the openfiledialog path"

and also.. i want to use a textbox and use it to type a description and save it to the txt file , so everytime i use next button it save the description i've typed and saved in a txt file , so it use the filepath right?? but if my filepath doesn't change at all how can i save the decription for every images i have??

as example i load the im1.jpg , and type the description , then i click next it loads the im2.jpg but the file path doesn't change , of course if i click the next button it change to the im3.jpg but the description file saved as "im1.txt" right??

please help me guys to finish this project , really need your help..

VS 2015 [RESOLVED] Merge cells in a DataTable

$
0
0
After a stroke, I am working on, to return to the programming world.
The problem I am trying to solve is that I import a CSV file to a DataTable with this:
Code:

        Dim dtArkivFonds As New DataTable(36)
        dtArkivFonds.Columns.AddRange _
        ( _
            {New DataColumn("MaterialeSignatur", GetType(String)), New DataColumn("RegistreringsNummer", GetType(Integer)), _
            New DataColumn("Særnummer", GetType(String)), New DataColumn("IndkomstJournalNr", GetType(String)), New DataColumn("StedNummer1", GetType(Integer)), _
            New DataColumn("StedNummer2", GetType(Integer)), New DataColumn("StedNummer3", GetType(Integer)), New DataColumn("Beskrivelse1", GetType(String)), _
            New DataColumn("Beskrivelse2", GetType(String)), New DataColumn("Beskrivelse3", GetType(String)), New DataColumn("Beskrivelse4", GetType(String)), _
            New DataColumn("Beskrivelse5", GetType(String)), New DataColumn("Beskrivelse6", GetType(String)), New DataColumn("Beskrivelse7", GetType(String)), _
            New DataColumn("Beskrivelse8", GetType(String)), New DataColumn("Beskrivelse9", GetType(String)), New DataColumn("Kategori1", GetType(String)), _
            New DataColumn("Kategori2", GetType(String)), New DataColumn("Kategori3", GetType(String)), New DataColumn("Kategori4", GetType(String)), _
            New DataColumn("YderÅr", GetType(String)), New DataColumn("MedarbejderSignature", GetType(String)), New DataColumn("IaltBind", GetType(Decimal)), _
            New DataColumn("IaltPakker", GetType(Decimal)), New DataColumn("IaltLæg", GetType(Decimal)), New DataColumn("Stiftet", GetType(String)), _
            New DataColumn("PakketBind", GetType(Decimal)), New DataColumn("PakketPakker", GetType(Decimal)), New DataColumn("PakketLæg", GetType(Decimal)), _
            New DataColumn("Nedlagt", GetType(String)), New DataColumn("HyldeMeter", GetType(Decimal)), New DataColumn("Bemærkninger", GetType(String)), _
            New DataColumn("RegistreringsDato", GetType(String)), New DataColumn("RegistreretAf", GetType(String)), New DataColumn("GodkendtAf", GetType(String)), _
            New DataColumn("Klausul1", GetType(String)), New DataColumn("Klausul2", GetType(String))} _
        )

        Dim csvData As String = File.ReadAllText(strFilePath & strFileName)
        For Each row As String In csvData.Split(ControlChars.Lf)

            If Not String.IsNullOrEmpty(row) Then
                dtArkivFonds.Rows.Add()

                Dim i As Integer = 0
                For Each cell As String In row.Split(";"c)

                    dtArkivFonds.Rows(dtArkivFonds.Rows.Count - 1)(i) = cell

                    i += 1
                Next

            End If

        Next

        GridView1.DataSource = dtArkivFonds
        GridView1.DataBind

It works fine, but I need to merge the fields "Beskrivelse1" to "Beskrivelse9" into a single field called "Beskrivelse"

I have tried to use this code, where I am getting an "Out Of Memory Exception"
Code:

If Not String.IsNullOrEmpty(row) Then
                dtArkivFonds.Rows.Add()

                Dim i As Integer = 0
                For Each cell As String In row.Split(";"c)

                    dtArkivFonds.Rows(dtArkivFonds.Rows.Count - 1)(i) = cell 'Read rows and puts data into cells

                    Dim dc As New DataColumn("Beskrivelse", GetType(String))                   
                        dc.Expression = "Beskrivelse1 + vbNewLine + Beskrivelse2 + vbNewLine + Beskrivelse3 + vbNewline + Beskrivelse4 + vbNewLine + Beskrivelse5 + vbNewLine + Beskrivelse6 + vbNewLine + Beskrivelse7 + vbNewLine + Beskrivelse8 + vbNewLine + Beskrivelse9"
                        dtArkivFonds.Rows.Add(dc)
                    i += 1
                Next

I know I have to resize the array, but I can't figure out how or if there is an another way to do it.
In the end all data have to be bulk copied into a SQL server

VS 2013 web browser write in element

$
0
0
need to write in element <div> this is the html code
<div id="t" class="message-tools__textarea js-scroller" contenteditable="true" data-placeholder="Write a message (Enter to send)">XXXXXX</div>
my ask is how write text like XXXXXX ?????

VS 2015 Advice Needed.. News Feed inside vb application

$
0
0
Hey everyone,

Just looking for a bit of advice actually. I was originally going to run a rss feed into my vb.net application via twitter but then i realized twitter no longer supports rss and neither do many other companies so is rss dying and if so what would be the best new way of updating news information within a vb application

All advice appreciated

Which syntax is better?

$
0
0
In vb.net we can create arrays in two ways. "Dim a as String()" and "Dim a() as String" are the two ways for creating new array. Which way is more smart and looks professional.
Thx

good source code library software

Block Show Desktop / Windows-D only for my app

$
0
0
Hello,
Please help me,
I want to stay on the desktop application when pressed lwin + d or show desktop button,
Topmost not want to stay in all the time,
fail at all :(

[RESOLVED] SetPixel does not set image to transparent

$
0
0
I have the following code and an image, that has transparent areas. I would like to set the mask to red. When running this, the entire mask is red, including what is supposed to be transparent.
Can someone help me fix this?

So how can I basically create a mask over the original image?

Code:

        Dim t As Color = Color.Transparent
        For y As Integer = 0 To 99
            For x As Integer = 0 To 99
                If m_Pic.GetPixel(x, y) <> t Then
                    m_Mask.SetPixel(x, y, Color.Red)
                End If
            Next
        Next

VS 2015, [ASK] how to make a zoom in and out on a picturebox image?

$
0
0
i'm trying to zoom in and out a picturebox image but i can't understand anything because i'm a newbie.. can you give me an example code that i can easily understand it??

The 'Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine.

$
0
0
The title says it all.

Running Visual Basic 2005 in Win10 x64bit

I recently researched about this . to change the app into x86 or x32 bit

but I have no options, there is no "Build" thingy in the properties. and there is no "Advance" in my Compile Section, what should I do?

VS 2015,[ASK] sort() command wrong sorting the list

$
0
0
hi all , i've tried the sort() command but the result is not as what i expecting . yeah it sorts my photos (i have 10 photos in a folder) and it sorts kinda like this : 1.jpg , 10,jpg , 2.jpg,3.jpg ,etc...

what i want is 1 - 10.jpg as numerical sort , but i know the list command i've created is using the (of string) command to calls the files and to sorts the files it's good , but back to what i want..

so is there anybody can show me the code to fix my problem??

how to declare data adapters and command bulder?

$
0
0
i need to use data adapters, command builders many times in my application? should i declare one module and declare them only once or declare one adapter for every sub procedure ? i think the first makes more sense but do i have to add something like 'dataadapter.clear' every time i use it?

VS 2015 PrintDocument1_PrintPage in PDF

$
0
0
Hello
could You help me. I'm looking for solutions to print in PDF my PrintDokument1.
I have made PrintDokument1 i my program, but i need it in PDF. ther is e.graphics.string and e.graphcs.drawline
can i use itextSharp to print one?
something like:
pdfdoc.open
pdfdoc.add(Printpage1.print)
pdfdoc.close

or any other solusions?
thank You for halp

VS 2013 vb.net instagram login without API

$
0
0
I'm trying to login to instagram without using their official api. I know this is possible and I'm pretty sure i'm very close to figuring out how.

Here's what I have so far.



1.Webrequest to get csrf token

Dim tempCookies As New CookieContainer
Dim postReq As HttpWebRequest = DirectCast(WebRequest.Create("https://instagram.com/accounts/login"), HttpWebRequest) postReq.CookieContainer = tempCookies
postReq.CookieContainer = tempCookies
Dim postresponse As HttpWebResponse
postresponse = DirectCast(postReq.GetResponse(), HttpWebResponse)
tempCookies.Add(postresponse.Cookies)
myCookie = tempCookies //myCookie is global




2. Using regex to get csrftoken
I'm getting the token correctly, checked multiple times.



3. Creating login webrequest

Dim postData As String = "username=user&password=pass"
Dim postReq As HttpWebRequest = DirectCast(WebRequest.Create("https://instagram.com/accounts/login/"), HttpWebRequest)
postReq.Method = "POST"
postReq.KeepAlive = True
postReq.CookieContainer = myCookie



Here's the problem: I don't know where to use the token. I tried adding it along with the postdata but it doesn't work. (I checked real webreq and token is not there in post) With this code, when I hit login its not logging in, i'm just getting the same loginpage again.

Also the page actually has some javascript before it loads the actual input fields, dont know if that makes a difference.

Hope someone helps.

VS 2010 IRC Channel user access.

$
0
0
Hi, I'm working in IRC project and I having a problem, I can't get user channel access, I mean check if he's Op or Hop or vop
(~, &, @, %, v)
Anyway to get it?

Need Help With a Rudimentary Translator

$
0
0
Hello all, I need help with a Rudimentary Translator. My teacher hasn't particular been of any help with Visual Basic at all, so I've been self teaching myself(quite poorly) for sometime now. The program is to take data from a "Dictionary.txt" file with languages such as English, French, German and Spanish and I have to have it translate from English to the latter languages. I have tried researching on ways to do this but all I have found has left me with someone stating that you shouldn't use a query before a for loop. I was wondering how I should go about querying my structure I have set up and selecting the relative translation of the words and outputting them onto the relative textboxes I have.

YES,OU,JA,SI
TABLE,TABLE,TISCH,MESA
THE,LA,DEM,LAS
IS,EST,IST,ES
YELLOW,JAUNE,GELB,AMARILLO
FRIEND,AMI,FREUND,AMIGO
SICK,MALADE,KRANK,ENFERMO
MY,MON,MEIN,MI
LARGE,GROS,GROSS,GRANDE
NO,NON,NEIN,NO
HAT,CHAPEAU,HUT,SOMBRERO
PENCIL,CRAYON,BLEISTIFT,LAPIZ
RED,ROUGE,ROT,ROJO
ON,SUR,AUF,EN
AUTO,AUTO,AUTO,AUTO
OFTEN,SOUVENT,OFT,A MENUDO

Here's how the text file looks

Code:

Public Class Form1
    Public Structure translator
        Dim english As String
        Dim french As String
        Dim german As String
        Dim spanish As String
    End Structure

    Dim trans() As translator


    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim translator() As String = IO.File.ReadAllLines("Dictionary.txt")
        Dim x As Integer = translator.Count - 1
        ReDim trans(x)
        Dim temp As String
        Dim sep() As String
        For i As Integer = 0 To x
            temp = translator(i)
            sep = temp.Split(","c)
            trans(i).english = sep(0)
            trans(i).french = sep(1)
            trans(i).german = sep(2)
            trans(i).spanish = sep(3)
        Next
    End Sub


    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim parseeng() As String = TextBox1.Text.ToUpper.Replace(".", "").Split(" "c)
        Dim frenchprase(parseeng.Count - 1) As String
        Dim gerprase(parseeng.Count - 1) As String
        Dim spaparse(parseeng.Count - 1) As String

        TextBox2.Clear()
        TextBox3.Clear()
        TextBox4.Clear()

        Dim count As Integer = parseeng.Count - 1

        Dim query = From t In trans
                    Where t.english.SingleOrDefault = parseeng()
                    Select t.french, t.german, t.spanish

    End Sub

End Class

Here's what I have so far. Hopefully my question is clear enough.

VS 2015 Enumeration Help

$
0
0
Hey all.

I'm learning Visual Basic .NET and am having some issues understanding enumeration and am wondering if anyone can help me figure out whats occurring here. I've spent around 6 hours trying to figure out how this works.

Here is the code I'm working with

Code:

Public Class Form1
    'DayAction Enumeration
  Private Enum DayAction As Integer
        Asleep = 0
        GettingReadyForWork = 1
        TravelingToWork = 2
        AtWork = 3
        AtLunch = 4
        TravelingFromWork = 5
        RelaxingWithFriends = 6
        GettingReadyForBed = 7
    End Enum
 
    'Declare Variable
  Private CurrentState As DayAction
 
    'Hour property
  Private Property Hour() As Integer
        Get
            'Return the current hour displayed
          Return dtpHour.Value.Hour
        End Get
        Set(value As Integer)
 
            'Set the date using the hour passed to this property
          dtpHour.Value = New Date(Now.Year, Now.Month, Now.Day, value, 0, 0)
 
            'Determin the state
          If value >= 6 And value < 7 Then
                CurrentState = DayAction.GettingReadyForWork
            ElseIf value >= 7 And value < 8 Then
                CurrentState = DayAction.TravelingFromWork
            ElseIf value >= 8 And value < 13 Then
                CurrentState = DayAction.AtWork
            ElseIf value >= 13 And value < 14 Then
                CurrentState = DayAction.AtLunch
            ElseIf value >= 14 And value < 17 Then
                CurrentState = DayAction.AtWork
            ElseIf value >= 17 And value < 18 Then
                CurrentState = DayAction.TravelingFromWork
            ElseIf value >= 18 And value < 22 Then
                CurrentState = DayAction.RelaxingWithFriends
            ElseIf value >= 22 And value < 23 Then
                CurrentState = DayAction.GettingReadyForBed
            Else
                CurrentState = DayAction.Asleep
            End If
 
            'Set the display text
          lblState.Text = "At " & value & ":00, Richard is " & CurrentState.ToString
        End Set
    End Property
 
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
        'Set the hour to the current hour
      Me.Hour = Now.Hour
    End Sub
 
    Private Sub dtpHour_ValueChanged(sender As Object, e As EventArgs) Handles dtpHour.ValueChanged
        'Update the hour property
      Me.Hour = dtpHour.Value.Hour
    End Sub
End Class

The Windows Form has a Date Time Picker named dtpHour and a label named lblState that displays what "Richard" is doing based on the time selected.

Can someone help me break down step by step whats happening?

I understand that I've declared my Enum at the top, what I don't understand is the Hour Property method (I understand the If / ElseIf statements and the label.Text statements - its everything above the If Statement).

I also am having trouble understating the dtpHour_ValueChange sub.
Viewing all 27186 articles
Browse latest View live


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