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

[RESOLVED] vb.net code generation for property "menustrip" failed error was project item unavail

$
0
0
Hi.
I used a menustrip and then I accidentally deleted the resource file.
Now every time i try to add an image to the menustrip I get this damn error.
I tried removing and adding the resource file but nothing.

Any help?!

Name:  Clipboard01.jpg
Views: 84
Size:  21.2 KB
Attached Images
 

how can i convert these code from VB6 to VB2010?

$
0
0
i found 1 nice way for chow animated images on richtextbox, but the code is from VB6 and i don't know convert it to VB2010. can anyone help me please?
Code:

'Inserts the picture at the current insertion point
Public Function InsertPicture(RTB As RichTextBox, pic As StdPicture)
Dim strRTFall As String
Dim lStart As Long
    With RTB
        .SelText = Chr(&H9D) & .SelText & Chr(&H81)
        strRTFall = .TextRTF
        strRTFall = Replace(strRTFall, "\'9d", PictureToRTF(pic))
        .TextRTF = strRTFall
        'position cursor past new insertion
        lStart = .Find(Chr(&H81))
        strRTFall = Replace(strRTFall, "\'81", "")
        .TextRTF = strRTFall
        .SelStart = lStart
    End With
End Function

'returns the RTF string representation of our picture
Public Function PictureToRTF(pic As StdPicture) As String
    Dim hMetaDC As Long, hMeta As Long, hPicDC As Long, hOldBmp As Long
    Dim Bmp As BITMAP, Sz As Size, Pt As POINTAPI
    Dim sTempFile As String, screenDC As Long
    Dim headerStr As String, retStr As String, byteStr As String
    Dim ByteArr() As Byte, nBytes As Long
    Dim fn As Long, i As Long, j As Long

    sTempFile = App.Path & "\~pic" & ((Rnd * 1000000) + 1000000) \ 1 & ".tmp"  'some temprory file
    If Dir(sTempFile) <> "" Then Kill sTempFile
   
    'Create a metafile which is a collection of structures that store a
    'picture in a device-independent format.
    hMetaDC = CreateMetaFile(sTempFile)
   
    'set size of Metafile window
    SetMapMode hMetaDC, MM_ANISOTROPIC
    SetWindowOrgEx hMetaDC, 0, 0, Pt
    GetObject pic.Handle, Len(Bmp), Bmp
   
    SetWindowExtEx hMetaDC, Bmp.Width, Bmp.Height, Sz
    'save sate for later retrieval
    SaveDC hMetaDC
   
    'get DC compatible to screen
    screenDC = GetDC(0)
    hPicDC = CreateCompatibleDC(screenDC)
    ReleaseDC 0, screenDC
   
    'set out picture as new DC picture
    hOldBmp = SelectObject(hPicDC, pic.Handle)
   
    'copy our picture to metafile
    BitBlt hMetaDC, 0, 0, Bmp.Width, Bmp.Height, hPicDC, 0, 0, vbSrcCopy
    'TransparentBlt hMetaDC, 0, 0, Bmp.Width, Bmp.Height, hPicDC, 0, 0, Bmp.Width, Bmp.Height, vbBlack
    'cleanup - close metafile
    SelectObject hPicDC, hOldBmp
    DeleteDC hPicDC
    DeleteObject hOldBmp
    'retrieve saved state
    RestoreDC hMetaDC, True
    hMeta = CloseMetaFile(hMetaDC)
    DeleteMetaFile hMeta
   
    'header to string we want to insert
    headerStr = "{\pict\wmetafile8" & _
                "\picw" & pic.Width & "\pich" & pic.Height & _
                "\picwgoal" & Bmp.Width * Screen.TwipsPerPixelX & _
                "\pichgoal" & Bmp.Height * Screen.TwipsPerPixelY & _
                " "
       
    'read metafile from disk into byte array
    nBytes = FileLen(sTempFile)
    ReDim ByteArr(1 To nBytes)
    fn = FreeFile()
    Open sTempFile For Binary Access Read As #fn
    Get #fn, , ByteArr
    Close #fn
    Dim nlines As Long
       
    'turn each byte into two char hex value
    i = 0
    byteStr = ""
    Do
        byteStr = byteStr & vbCrLf
        For j = 1 To 39
            i = i + 1
            If i > nBytes Then Exit For
            byteStr = byteStr & Hex00(ByteArr(i))
        Next j
    Loop While i < nBytes
   
    'string we will be inserting
    retStr = headerStr & LCase(byteStr) & vbCrLf & "}"
    PictureToRTF = retStr
   
    'remove temp metafile
    Kill sTempFile

End Function

'adds leading zero to hex value if needed.
Public Function Hex00(icolor As Byte) As String
    Hex00 = Right("0" & Hex(icolor), 2)
End Function

on VB2010 we don't use(for exemple) 'StdPicture', but 'image', but i don't know convert it.
can anyone help me, please?

move may form icon

$
0
0
Hi.
Is there a way to move the form main icon to the right?
Thanks.

VS 2017 How to rotate jpeg images ?

$
0
0
Hi All,

I have lots of jpeg images that have text and images displayed in landscape mode (or horizontally).

Is there a VB. NET code/way to rotate the images 90 degrees so that the images/text will display in "portrait" modes before saving back to jpeg file format for printing.

I am using VS 2017 Community version on Windows 10.

Thank you in advance

VS 2017 [RESOLVED] How do I paste an entire project (form GUI, etc)

$
0
0
Want someone to run my small project.
Instead of sending project folder, I just want him to paste the whole designer code (and event code)
How can I access this?

VS 2010 how we add images using RTF?

$
0
0
how we add images using RTF?
i'm trying without sucess :(
Code:

Public Function imageToHex(img As Image) As String

        Dim ms As New MemoryStream
        img.Save(ms, ImageFormat.Png)

        Dim bytes() As Byte = ms.ToArray()

        Dim hex As String = BitConverter.ToString(bytes)
        Return hex.Replace("-", "")
    End Function

    Public Sub InsertImageRTF(ByVal strImage As String)
        Dim btFileStream() As Byte
        btFileStream = My.Computer.FileSystem.ReadAllBytes(strImage)
        'RichTextBox1.Text = System.Text.Encoding.UTF7.GetString(btFileStream)
        Dim s As Image = Image.FromFile(strImage)
        Dim strRTF As String = ""
        strRTF = "{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 Calibri;}}{\*\generator Msftedit 5.41.21.2510;}\viewkind4\uc1\pard\sa200\sl276\slmult1\lang9\f0\fs22 testing\par\par\pard\sa200\sl240\slmult1{\pict\wmetafile8\" + s.Width.ToString + "\pich" + s.Height.ToString + "\picwgoal5924\pichgoal1860 hex " + imageToHex(s) + "}}"
        Me.Rtf = strRTF
        Debug.Print(Me.Rtf)
    End Sub

the debug give me:
"{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 Calibri;}}
{\*\generator Msftedit 5.41.21.2512;}\viewkind4\uc1\pard\sa200\sl276\slmult1\lang9\f0\fs22 testing\par
\par
\pard\sa200\sl240\slmult1 31\par
}"
means that the image data isn't added.
can anyone advice me?

VS 2010 SQL Database help

$
0
0
I currently have a SQL database that is on disk, and as such the SQL commands are quite slow. Is it possible to effectively load the SQL database into memory and run the query(s) against the memory rather than the disk ?

Data type and array declaration

$
0
0
Hi All,

I make a short code as seen below and it gives me the error of "Type mis-match". I have tried to use Long(), Double(), and Object() but none of them has not been worked at all.
What would the data type and array declaration are correct?

Any help is much appreciated.


Code:

Private Sub iPartColor(ByRef R As Long, ByRef G As Long, ByRef B As Long, myCAT As Object)

        ' //// Define object selection
        Dim oSel As INFITF.Selection
        oSel = myCAT.ActiveDocument.Selection

        '//// Search and save all surfaces in active document in oSelection collection
        oSel.Search("Topology.Face.Color = *, All")

        Dim DefaultVisProperties '//// As VisProperty
        DefaultVisProperties = myCAT.ActiveDocument.Selection.visProperties

        Dim colorArray As Long() = {R, G, B}
        '//// Get PartBody's default color
        DefaultVisProperties.GetRealColor(colorArray) '// Error is right on this line " Type mis-matched"

    End Sub


Search Button in vb.net

$
0
0
I have Table Called "ItemsPricesTbl"

Contain :

ItemID
FirstUnitWholeSalePrice
FirstUnitShopperPrice
FirstUnitDemotionsPrice
FirstUnitPriceDefult
SecondUnitWholeSalePrice
SecondUnitShopperPrice
SecondUnitDemotionsPrice
SecondUnitPriceDefult
ThirdUnitWholeSalePrice
ThirdUnitShopperPrice
ThirdUnitDemotionsPrice
ThirdUnitPriceDefult
DefultPrice


The Stored Porc is :


Code:

ALTER PROCEDURE [dbo].[Get_Prices_Item_By_ID]
 
@ItemID int
 
as
 
begin
 
Select ItemID,FirstUnitWholeSalePrice,FirstUnitShopperPrice,FirstUnitDemotionsPrice,FirstUnitPriceDefult,SecondUnitWholeSalePrice,SecondUnitShopperPrice,SecondUnitDemotionsPrice,SecondUnitPriceDefult,ThirdUnitWholeSalePrice,ThirdUnitShopperPrice,ThirdUnitDemotionsPrice,ThirdUnitPriceDefult,DefultPrice from ItemsPricesTbl Where ItemID=@ItemID
 
End


in Vb i have DatabaseManager Class Which Have this Code :


Code:

Private Function exeReader(ByRef cmd As SqlCommand, ByRef dr As SqlDataReader) As Integer
        Dim retval As Integer = -1
        cmd.Connection = Me.Connection
        Try
            If cmd.CommandType = CommandType.StoredProcedure Then
                Dim pr As New SqlParameter("@retval", SqlDbType.Int)
                pr.Direction = ParameterDirection.ReturnValue
                cmd.Parameters.Add(pr)
            End If
            If cmd.Connection.State = ConnectionState.Closed Then cmd.Connection.Open()
            dr = cmd.ExecuteReader()
 
            If cmd.CommandType = CommandType.StoredProcedure Then retval = cmd.Parameters("@retval").Value
        Catch ex As Exception
            Throw New Exception(ex.Message)
        Finally
            Me.close()
        End Try
 
        Return retval
    End Function


Also I have two classes The Data Class And Business Class .

Data Class Code :


Code:

Friend Function Get_Prices_Item_By_ID(ByRef cmd As SqlCommand, ByRef dr As SqlDataReader, ByVal ItemID As Integer) As Integer
            Dim retval As String
            cmd = New SqlCommand("Get_Prices_Item_By_ID")
            daa.SelectCommand.Parameters.AddWithValue("@FirstUnitWholeSalePrice", SqlDbType.Decimal)
            daa.SelectCommand.Parameters.AddWithValue("@FirstUnitShopperPrice", SqlDbType.Decimal)
            daa.SelectCommand.Parameters.AddWithValue("@FirstUnitDemotionsPrice", SqlDbType.Decimal)
            daa.SelectCommand.Parameters.AddWithValue("@FirstUnitPriceDefult", SqlDbType.Bit)
            daa.SelectCommand.Parameters.AddWithValue("@SecondUnitWholeSalePrice", SqlDbType.Decimal)
            daa.SelectCommand.Parameters.AddWithValue("@SecondUnitShopperPrice", SqlDbType.Decimal)
            daa.SelectCommand.Parameters.AddWithValue("@SecondUnitDemotionsPrice", SqlDbType.Decimal)
            daa.SelectCommand.Parameters.AddWithValue("@SecondUnitPriceDefult", SqlDbType.Bit)
            daa.SelectCommand.Parameters.AddWithValue("@ThirdUnitWholeSalePrice", SqlDbType.Decimal)
            daa.SelectCommand.Parameters.AddWithValue("@ThirdUnitShopperPrice", SqlDbType.Decimal)
            daa.SelectCommand.Parameters.AddWithValue("@ThirdUnitDemotionsPrice", SqlDbType.Decimal)
            daa.SelectCommand.Parameters.AddWithValue("@ThirdUnitPriceDefult", SqlDbType.Bit)
            daa.SelectCommand.Parameters.AddWithValue("@DefultPrice", SqlDbType.Int)
            dr = cmd.ExecuteReader()
            Return retval
        End Function

And Business Class Code :

Code:

Public Function Get_Prices_Item_By_ID(ByVal ItemID As Integer) As DataTable
    Dim dt As New DataTable
    p.Get_Prices_Item_By_ID(dt)
    Return dt
End Function


What Code I have to Put in search Button ?

And How To Display Record From SQL To TextBox ?

Help needed with a few lines of code (simple code for most of you).

$
0
0
I am developing a Windows application program using Visual Studio 2017. Hopefully this is the correct forum, if not, I apologize.

I want a button to execute an .exe program that is either stored in Program Files or Program Files (x86) folder.

I have no problem to specify one location (e.g. Program Files) but seem to be having problems with searching for the program in the second location (e.g. Program Files (x86), if not found in the first location.

Your help would be greatly appreciated. My code is as follows (as is obvious, I also have a reminder pop-up and a message pop-up). I've only included the code that succeeded:

Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click

Dim Key As RegistryKey = Registry.CurrentUser.OpenSubKey("Software\DontAskAgain1")

If Key Is Nothing Then

Reminder1.ShowDialog()

End If

Try
System.Diagnostics.Process.Start("C:\Program Files\Malwarebytes Anti-Malware\mbam.exe")

Catch ex As Exception
MsgBox("Program is either not installed or is installed in the wrong location." & vbNewLine & "View the AZFL 'Info' page for program information and download.",
MsgBoxStyle.Exclamation,
"AZFL cannot find Malwarebytes' Anti-Malware")

End Try

End Sub

VS 2015 Title Case The Textbox

$
0
0
a help is needed!

i have a textbox which allow me to input a string.

question: now i wanna to automatically "Title Case format as" the string in textbox when
a is string input in this textbox. so how should i write the code?

Example: when i input "home" it will display in that textbox as "Home" .(without on the Caps Lock).

thanks for the help!

Close file handle

$
0
0
Sorry if this is a simple/dumb question, but I've hit another little snag.

I have an application which allows users to store a photo of customers within it. The app allows it through an OpenFile dialog, in which the user selects an image from anywhere, which is then copied to a specific folder inside the application data folder.

Thing is: Should the user wish to replace that photo with another with the same filename, I would need to close the application's handle with the file before I could remove it. Whats the code required to close a file handle so I can remove that file without ending the application's process?

Calling sub's

$
0
0
Hi All,

I try to learn how to call sub's in different modules in the same project/solution but it seems not working. Please see my simple demo below. I tried Sub Main() to call TEST() but it is not working as well.

Code:

Module Module1

    Private Sub callTEST()

        TEST()

    End Sub

End Module
'------------------------

Module Module2

Public Sub TEST()

        MsgBox("HERE")

    End Sub

End Module

How could I call TEST() properly to get TEST() to work?
Can I pass parameters from TEST() to callTEST()?

Any help is much appreciated

Thanks All

Custom color picker - Luminance slider for picked colour

$
0
0
Hi guys,

I'm trying to create a custom color picker, which would be something like ColorDialog is.
Reason I can't use ColorDialog is because I don't want a pop-up window and more importantly I want to use same color picker for saving 3 different colors in order to set my app background color as gradient. That would take me 3 different ColorDialogs with buttons and options I don't need.

I've managed to create a custom color picker where I select a color from color palette image and save those colors If I want them by a mouse click. code is actually pretty simple (only a snapshot):

Code:

Private Sub Picturebox1_MouseMove(sender As Object, e As MouseEventArgs) Handles Picturebox1.MouseMove
        On Error Resume Next
        Dim img As Bitmap
        img = Picturebox1.BackgroundImage
        Dim iY, iX
        iX = (MousePosition.X - Me.Left - Me.pcbBarve.Left) * (img.Width / Me.pcbBarve.Width)
        iY = (MousePosition.Y - Me.Top - Me.pcbBarve.Top) * (img.Height / Me.pcbBarve.Height)

        Dim c As Color = img.GetPixel(iX, iY)

        'Im displying RGB values of color picked in Textboxes
        If ShowRGB = True Then
            TextBox2.Text = c.R
            TextBox1.Text = c.G
            TextBox3.Text = c.B
        End If
     
    End Sub

Only problem I'm facing is the right scroll or track bar like this one in ColorDialog (Red border around slider I'm taking about):

Name:  Color.png
Views: 25
Size:  24.1 KB

As far as I know this is a Luminance slider (or Saturation ??). How can I create It ? I want the same functionality as in Colordialog is - so when you scroll over some color in color palette, Luminance for picked color should change too, and draw brightness of this color. I want this scroll to let user pick brightness amount of picked colour.

I hope you understand me, I don't know If I even described It correctly, I jut don't find any good & simple example of how to do this. Thanks in advance !!
Attached Images
 

SQL Local db - instances

$
0
0
Whilst trying to work out what is the best datadbase to use, I have been researching what the sql localdb provides for developers.

Looking at it, it appears that you can create more than one instance of the localdb (sqllocaldb), which can all run at the same time. Within each instance, you can create a number of databases. However irrespective of which instance you use, the db files are all put in the same physical location. So you could have a conflict of database physical file names, despite them being separate databases running on different instances of the Local db.

What is the benefit / purpose of being able to run more than one instance of the local db. (Sqllocaldb) ?

VS 2015 Need Help: Argument not specified for parameter 'sender (and e) ' of 'private sub'

$
0
0
Greetings,
I'm following a VB tutorial on how to make MineSweeper (Link: https://www.youtube.com/watch?v=YJP0...66177&index=15)
Tom's tutorial's code has changed between videos so I've got errors:
1. AddHandler C.MouseClick, AddressOf MineClick()
- Error: Argument not specified for parameter 'sender' of 'Private Sub MineClick(sender As Object, e as Mouse EventArgs)'
- Error: Argument not specified for parameter 'e' of 'Private Sub MineClick(sender As Object, e as Mouse EventArgs)'

The Sub it's referring to is this:

Private Sub MineClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)

Dim M As MineCell1 = sender
If e.Button = MouseButtons.Left Then
If M.HasMine Then
For Each MC As MineCell1 In MineField
If MC.HasMine Then MC.view = Mine
MC.Refresh()
Next
End If
If M.Number > 0 Then
M.view = Number
M.Refresh()
End If

'------------------------------------------------------------
ElseIf e.Button = MouseButtons.Right Then
Select Case M.view
'Blank cell right click
Case Button
M.view = Flag
M.Refresh()
'Flagged mine cell right click
Case Flag
M.view = Question
M.Refresh()
Case Else
M.view = Button
M.Refresh()
End Select
End If
End Sub
'Each case is referring to an enum called MineCell1

Another bug, but I think it'll go away if we fix the AddHandler error:
The bold part of the code is supposed to change the view of the MineCells when you click on them (change to a mine, number etc) But when I left click click on them nothing happens. The right click works (puts a flag or a question mark on the MineCell).

If anyone could give advice on a potential fix that'd me much appreciated. I've also attached a pdf file with all my code if you want to refer to it.
Attached Images

VS 2017 [RESOLVED] Update DataSet after Bound DGV has been Cleared

$
0
0
I have a Bound DGV, with a BindingSource. I need to clear the DGV before adding a new set of records. The clearing of the DGV I have working.

The problem is when I add the new records a bunch of blank lines appear after the new list of records. I am assuming that this is because the DataSet has not been updated to reflect the DGV changes, before the new records are added. I have searched for a solution and cannot find one that works. One that will add the new data without the extra rows.

Anyone have a solution.


Code:

        DGVScadaEquipmentGeneration.DataSource = Nothing
        DGVScadaEquipmentGeneration.Rows.Clear()
        DGVScadaEquipmentGeneration.Refresh()

        DGVScadaEquipmentGeneration.DataSource = TbEquipmentScadaBindingSource
        DsProjectData.AcceptChanges()

        <Add New List Here .....>

VS 2015 Problems understanding UWP HttpClient POST...

$
0
0
Afternoon all,

I've been researchuing this most of today but can't seem to find many examples and even less that actually make sense...

I have a Web API running on a local machine that has a POST test route on it, works fine from Postman, if I post 'key Test' and 'Value Blarblarblar' then it returns "{ "test": "blarblarblar"}".

Desperately trying to get UWP VB to do the same but don't seem to be able to make any headway.

Code:

Dim Content As HttpContent = New StringContent("test test test")
Using http As New HttpClient()
    Using response As HttpResponseMessage = Await http.PostAsync("http://192.168.1.103/api/posttest", Content)
        Dim result = Await response.Content.ReadAsStringAsync()
        Using ms = New MemoryStream(Encoding.UTF8.GetBytes(result))
        End Using
    End Using
End Using

I'm not getting any error messages, in the responce I'm getting a 'status code:200' and a 'reason phrase:OK'. I have a sneaky feeling i shouldn't just be sending 'test test tets' I think I should be sending a key and a value, I just can't work out how.... any ideas or pointers...?

Thanks

Dave

get progress boar progress to the form, from another class.

$
0
0
Hi.
So I have a form and the form calls another class.
The issue is that the progress board is not getting updated with the values (it actually shows but the green counter is not updating).
Another note. I can see the counter updating if i run it on debug an see one by one the values, but at real time it just show empty.

Here is some code:
Code:

'Form
  Dim LDMS As New List(Of DMS)
        If cGeneral.FillDMS(DtSet, LDMS, Me, iexcelcount) = False Then
       
            Me.Close()
            Exit Sub
        End If

So I call the FillDMS function from another class.
Code:

  Friend Function FillDMS(ByVal ds As DataSet, ByRef DMSList As List(Of DMS), ByRef frm As Form2, i As Integer) As Boolean
        Dim Dt As New DateTime
        Dim strDateFrom As String
        Dim dc As Double

        frm.ProgressBarExcelLoad.Visible = True
        frm.ProgressBarExcelLoad.Minimum = 1
        frm.ProgressBarExcelLoad.Maximum = i
        frm.ProgressBarExcelLoad.Value = 1
        frm.ProgressBarExcelLoad.Step = 1

  Try

            For Each row As DataRow In ds.Tables("Voucher").Rows

''etc
  DMSList.Add(cl)
                frm.ProgressBarExcelLoad.PerformStep() ' step +
next

return

I used both byref and byval for the form btw.
any idea?
thanks.

VS 2010 MP4 Video Downloader - Help

$
0
0
Hi
I need some help, can anyone help me in your free time to create applications that will be able to download MP4 videos through links placed in TextBox, but also to be able to choose video quality like (High, Normal, Low) or (1080p, 720p, etc.) in other words (every quality that is possible from that Link - Video)
Or if anyone knows a good program to suggest me it will be big help.
I know that maybe this post is not in a suitable place, and maybe i looking too much.
Sorry :(
Thank you!
Viewing all 26515 articles
Browse latest View live




Latest Images