Symbianize Forum

Most of our features and services are available only to members, so we encourage you to login or register a new account. Registration is free, fast and simple. You only need to provide a valid email. Being a member you'll gain access to all member forums and features, post a message to ask question or provide answer, and share or find resources related to mobile phones, tablets, computers, game consoles, and multimedia.

All that and more, so what are you waiting for, click the register button and join us now! Ito ang website na ginawa ng pinoy para sa pinoy!

VB.NET Programming Corner!

dim num as integer

int32.tryparse(cmd.executescalar, num)


TS! ginawa ko na yung pinost mo na code, ganun pa din error eh!
 
sa computer po mismo sir ... hirap po kc d aq makakita sa goolge puro c# help me po .

here's a sample code, this will resize the image to a thumbnail, nasa button browse ang code na to (gawa ka nalang ng button)

Code:
Imports System.Windows.Forms
Imports System.Drawing
Imports System.IO

Private Const INT_h As Integer = 170 ' resize to desired thumbnail size

Private Sub btnBrowse_Click(sender As Object, e As EventArgs) Handles btnBrowse.Click
        Dim OpenFile As New OpenFileDialog
        Dim result As DialogResult
        Dim File As String
        Dim w As Integer = INT_h
        Dim h As Integer = INT_h

        Try
            With OpenFile
                .Filter = "JPG|*.jpg|JPEG|*.jpeg|BMP|*.bmp|PNG|*.png|ALL|*.*"
                .Multiselect = True
                .Title = "Image Upload"
                result = .ShowDialog()
            End With

            If result = Windows.Forms.DialogResult.OK Then
                Dim myBitmapSmall As Bitmap

                For Each File In OpenFile.FileNames
                    Dim myControl As New ucPictureBox ' this user control has a picturebox (pb), a textbox (txt), 2 buttons (btnClose and btnPreview)
                    myBitmapSmall = New Bitmap(w, h)
                    Using g As Graphics = Graphics.FromImage(myBitmapSmall)
                        g.DrawImage(New Bitmap(File), 0, 0, w, h)
                    End Using

                    With myControl
                        .ImageLocation = File
                        .pb.Image = myBitmapSmall
                        .txt.Text = Path.GetFileNameWithoutExtension(File)
                        .ImageExt = Path.GetExtension(File)
                        .ImageId = 0 ' under sa ucPictureBox, mag declare ka ng ImageId
                    End With

                    FlowLayoutPanel1.Controls.Add(myControl) ' may flowlayoutpanel sa form, para e dagdag nya ang control (ucPictureBox) sa form.

                    System.Threading.Thread.Sleep(200)
                Next
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

note: ni strip ko lang tong code sa actual codes ko, might run, might not, but you have something to start with. (the code is not compiled)

- - - Updated - - -

dim num as integer

int32.tryparse(cmd.executescalar, num)


TS! ginawa ko na yung pinost mo na code, ganun pa din error eh!

try mo to:

dim num as integer = 0
dim x as object
x = cmd.executescalar
if not isdbnull(x) then
num = convert.toint32(x)
end if

note: untested, coding on the fly
 

Attachments

  • sample.png
    sample.png
    80.2 KB · Views: 7
Paano po yung way niyo para masave sa database yung primary key(id) ng isang row kung ang makukuha niyong value e ung other column?

example:

student id | student name | age |
1 Yaki Udon 48


Ang nasa combo box ko e ung list of student names na pag sesave ko sa database, ikequery ko muna yung student name sa dataset para makuha ung student id at isave sa database. Ano po bang best way para mapadali to? Help please. Thanks.
 
Paano po yung way niyo para masave sa database yung primary key(id) ng isang row kung ang makukuha niyong value e ung other column?

example:

student id | student name | age |
1 Yaki Udon 48


Ang nasa combo box ko e ung list of student names na pag sesave ko sa database, ikequery ko muna yung student name sa dataset para makuha ung student id at isave sa database. Ano po bang best way para mapadali to? Help please. Thanks.

pag load mo sa combobox, e set mo ang displaymember at valuemember,

combobox1.valuemember = "studentId"
combobox1.displaymember = "student_name"

pag kuha mo ng value

mystudentId = combobox1.selectedvalue

*** EDIT ***
i forgot
combobox1.datasource = myDataTable ' where your datatable should contain your data from the database
 
Last edited:
here's a sample code, this will resize the image to a thumbnail, nasa button browse ang code na to (gawa ka nalang ng button)

Code:
Imports System.Windows.Forms
Imports System.Drawing
Imports System.IO

Private Const INT_h As Integer = 170 ' resize to desired thumbnail size

Private Sub btnBrowse_Click(sender As Object, e As EventArgs) Handles btnBrowse.Click
        Dim OpenFile As New OpenFileDialog
        Dim result As DialogResult
        Dim File As String
        Dim w As Integer = INT_h
        Dim h As Integer = INT_h

        Try
            With OpenFile
                .Filter = "JPG|*.jpg|JPEG|*.jpeg|BMP|*.bmp|PNG|*.png|ALL|*.*"
                .Multiselect = True
                .Title = "Image Upload"
                result = .ShowDialog()
            End With

            If result = Windows.Forms.DialogResult.OK Then
                Dim myBitmapSmall As Bitmap

                For Each File In OpenFile.FileNames
                    Dim myControl As New ucPictureBox ' this user control has a picturebox (pb), a textbox (txt), 2 buttons (btnClose and btnPreview)
                    myBitmapSmall = New Bitmap(w, h)
                    Using g As Graphics = Graphics.FromImage(myBitmapSmall)
                        g.DrawImage(New Bitmap(File), 0, 0, w, h)
                    End Using

                    With myControl
                        .ImageLocation = File
                        .pb.Image = myBitmapSmall
                        .txt.Text = Path.GetFileNameWithoutExtension(File)
                        .ImageExt = Path.GetExtension(File)
                        .ImageId = 0 ' under sa ucPictureBox, mag declare ka ng ImageId
                    End With

                    FlowLayoutPanel1.Controls.Add(myControl) ' may flowlayoutpanel sa form, para e dagdag nya ang control (ucPictureBox) sa form.

                    System.Threading.Thread.Sleep(200)
                Next
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
Sir tnx po for this but i need po ung file explorer and viewer po help me po
 
here's a sample code, this will resize the image to a thumbnail, nasa button browse ang code na to (gawa ka nalang ng button)

Code:
Imports System.Windows.Forms
Imports System.Drawing
Imports System.IO

Private Const INT_h As Integer = 170 ' resize to desired thumbnail size

Private Sub btnBrowse_Click(sender As Object, e As EventArgs) Handles btnBrowse.Click
        Dim OpenFile As New OpenFileDialog
        Dim result As DialogResult
        Dim File As String
        Dim w As Integer = INT_h
        Dim h As Integer = INT_h

        Try
            With OpenFile
                .Filter = "JPG|*.jpg|JPEG|*.jpeg|BMP|*.bmp|PNG|*.png|ALL|*.*"
                .Multiselect = True
                .Title = "Image Upload"
                result = .ShowDialog()
            End With

            If result = Windows.Forms.DialogResult.OK Then
                Dim myBitmapSmall As Bitmap

                For Each File In OpenFile.FileNames
                    Dim myControl As New ucPictureBox ' this user control has a picturebox (pb), a textbox (txt), 2 buttons (btnClose and btnPreview)
                    myBitmapSmall = New Bitmap(w, h)
                    Using g As Graphics = Graphics.FromImage(myBitmapSmall)
                        g.DrawImage(New Bitmap(File), 0, 0, w, h)
                    End Using

                    With myControl
                        .ImageLocation = File
                        .pb.Image = myBitmapSmall
                        .txt.Text = Path.GetFileNameWithoutExtension(File)
                        .ImageExt = Path.GetExtension(File)
                        .ImageId = 0 ' under sa ucPictureBox, mag declare ka ng ImageId
                    End With

                    FlowLayoutPanel1.Controls.Add(myControl) ' may flowlayoutpanel sa form, para e dagdag nya ang control (ucPictureBox) sa form.

                    System.Threading.Thread.Sleep(200)
                Next
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
Sir tnx po for this but i need po ung file explorer and viewer po help me po

there is an easy way and a hard way, easy way muna: if hindi contented sa easy way, then we go the hard way.

Code:
Try
' 
            If ImageId <= 0 Then
                MsgBox("Could not locate specified image on database.", MsgBoxStyle.OkOnly, "")
                Exit Sub
            End If

            Dim mData As New DataTable
            Dim mCommand As New MySqlCommand

            mCommand.CommandText = "SELECT columns FROM db_table WHERE column = @imageId;"
            mCommand.Parameters.AddWithValue("@imageId", ImageId)

            mData = mySQL.ExecuteQuery(mCommand) ' function ko to query sa database

            If mData IsNot Nothing Then ' cross checking if result has rows
                If mData.Rows.Count > 0 Then ' i am sure na may record akong nakuha
                    Dim ImageRawData() As Byte = mData.Rows(0).Item("image") ' first item ng result
                    Dim FileName As String

                    If mData.Rows(0).Item("imageFileName").ToString = "" Then
                        FileName = RandomStr() & mData.Rows(0).Item("extension").ToString ' put a random name to the file being fetched if blank
                    Else
                        FileName = String.Format("{0}{1}", mData.Rows(0).Item("imageFileName").ToString, mData.Rows(0).Item("extension").ToString) ' use its file name
                    End If

                    Process.Start(WriteToTempFile(ImageRawData, FileName)) ' open with default image viewer na naka install sa computer (e.g. mspaint, windows photo viewer)
' dito mo e alter si hard way, gawa ka ng sariling form na may picturebox and other functions like zoom, drag, etc... then itapon mo ang ImageRawData to the picturebox
                End If
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

    Public Shared Function WriteToTempFile(ByVal ImageRawData() As Byte, ByVal FileName As String) As String
        ' Writes image to a temporary file and returns path
        Dim strFilename As String = System.IO.Path.Combine(My.Computer.FileSystem.SpecialDirectories.Temp, FileName)
        Dim objFS As New System.IO.FileStream(strFilename, System.IO.FileMode.Append, System.IO.FileAccess.Write)

        objFS.Write(ImageRawData, 0, ImageRawData.Length)
        objFS.Flush()
        objFS.Close()
        Return strFilename
    End Function

    Public Function RandomStr() As String
        Const s As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
        Dim r As New Random
        Dim sb As New StringBuilder
        For i As Integer = 1 To 8
            Dim idx As Integer = r.Next(0, 35)
            sb.Append(s.Substring(idx, 1))
        Next
        Return sb.ToString
    End Function

anyway, code is untested. i did not compile it.
 
hai mga masters in programming... :)

first time ko po bumisita dto sa www.symbianize.com/ at kailangan ko po ng tulong.. sa aking VB.net project

asking help po sa SMS application... sa VB.net ko po balak gawin ang SMS app at nag research ndin po ako ng ibang information about sa SMS app pero ndi pa po spat ang mga nahanap ko, sna po mabigyan nui pa po ako ng ibang info at tutorials how to work with SMS app.. tsaka nga po pla MS SQL server 2008 ang gmit kung DB..

one problem pa po ay working at LANetwork i have a database in my server machine using MS SQL server 2008 at may naka connect sa server machine na 3 clients computer (connected using switch and UTP cables) ang prob po ndi ko po alam kung paano i configure si MSSQL pra ma access ng clients and DB sa sql... at iba pa factors para nakagawa ng client/server base application.. im using VB.net 12..

thank you po in advance...
please pa help po.. i need masters... :)
 
Last edited:
Pa help naman po pls alam ko pong sobrang dali lang po nito sa mga programming masters d2 1st time ko din po huminge ng tulong sana po matulungan nyu ko ito po yung sample output . kasi po papatayin na ko ng nanay ko pag nabagsak ko po iton programming group project po kasi namin to help naman po.
 

Attachments

  • 123.jpg
    123.jpg
    86.5 KB · Views: 11
guys, pano ko gagawin sa program ko yung pwede niya i-calculate yung years and months sa company yung tenures ng isang employee? salamat po.

- - - Updated - - -

guys, pano ko gagawin sa program ko yung pwede niya i-calculate yung years and months sa company yung tenures ng isang employee? salamat po.

na-solve ko na po ito guys, hehe! pasensiya na po.
 
For Each s In images
If s.Extension.ToLower = ".png" Or s.Extension.ToLower = ".jpg" Or s.Extension.ToLower = ".bmp" Or s.Extension.ToLower = ".gif" Or s.Extension.ToLower = ".tif" Then
If newLocx >= PictureBox1.Width - swidth - 10 Then
newLocx = locx
locy = locy + sheight + 30
newLocy = locy
Else
newLocy = locy
End If
loadimg(s.Name, s.FullName, newLocx, newLocy)
newLocx = newLocx + swidth + 10
newLocy = locy + sheight + 10

End If
Next

Paano ko po makukuha ung bawat file name nung pictures dyan ?
 
Last edited:
mga sir.. pahelp naman po.. about time and date... bakit po kapag nag sasave aq ng date from datetimepicker laging may kasamang time?.. binago qna po ung format nya into shortdatetime.. kaso ganun padin pag lumalabas sa listview
ex: 12/12/1993 12:00:00 any solution po?.. :(
 
Last edited:
Patambay poh muna dito sir basa mode poh baka may matutunan poh.
 
For Each s In images
If s.Extension.ToLower = ".png" Or s.Extension.ToLower = ".jpg" Or s.Extension.ToLower = ".bmp" Or s.Extension.ToLower = ".gif" Or s.Extension.ToLower = ".tif" Then
If newLocx >= PictureBox1.Width - swidth - 10 Then
newLocx = locx
locy = locy + sheight + 30
newLocy = locy
Else
newLocy = locy
End If
loadimg(s.Name, s.FullName, newLocx, newLocy)
newLocx = newLocx + swidth + 10
newLocy = locy + sheight + 10

End If
Next

Paano ko po makukuha ung bawat file name nung pictures dyan ?

that would depend kung saan mo nilagay ang filename sa "Images", try s.Name.ToString

- - - Updated - - -

mga sir.. pahelp naman po.. about time and date... bakit po kapag nag sasave aq ng date from datetimepicker laging may kasamang time?.. binago qna po ung format nya into shortdatetime.. kaso ganun padin pag lumalabas sa listview
ex: 12/12/1993 12:00:00 any solution po?.. :(

dim myDate as string = format(datetimepicker1.value,"yyyy-MM-dd")
msgbox(myDate)
 
mga sir.. pahelp naman po.. about time and date... bakit po kapag nag sasave aq ng date from datetimepicker laging may kasamang time?.. binago qna po ung format nya into shortdatetime.. kaso ganun padin pag lumalabas sa listview
ex: 12/12/1993 12:00:00 any solution po?.. :(

sa settings lang ng datetimepicker yan, naka-long kasi yung format niya change mo into short format

View attachment 226975
 

Attachments

  • Untitled.png
    Untitled.png
    12.2 KB · Views: 5
nakaadministrator mode naman ako sir nun...nagreinstall ako ng panibagong vb.net umayos na po...salamat nalang po...
 
guys, ano mali dito sa code ko? kasi pag nag-vview na ng records ndi lumalabas yung selected data eh! sa crystal report. Pero Nag-vview naman yung report wala lang data. by the way i'm using VS2013 and Crystal Report

Private Sub FrmProfile_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim cryRpt As New ReportDocument

cn.Open()
With cmd
.Connection = cn
.CommandText = "SELECT * FROM employee WHERE ID = " & FrmProfileGridView.MTProfile.SelectedRows(0).Cells(0).Value.ToString() & ""
End With

da.SelectCommand = cmd
dt15.Clear()
da15.Fill(dt15)
FrmProfileGridView.MTProfile.DataSource = dt15
cryRpt.Load("C:\empsys\WindowsApplication3\empprofile.rpt")
CrystalReportViewer1.SelectionFormula = " {employee.Emp_ID} = '" & FrmProfileGridView.MTProfile.SelectedCells(0).Value & "'"
CrystalReportViewer1.ReportSource = cryRpt
CrystalReportViewer1.Refresh()
cn.Close()
End Sub
 
guys, ano mali dito sa code ko? kasi pag nag-vview na ng records ndi lumalabas yung selected data eh! sa crystal report. Pero Nag-vview naman yung report wala lang data. by the way i'm using VS2013 and Crystal Report

Private Sub FrmProfile_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim cryRpt As New ReportDocument

cn.Open()
With cmd
.Connection = cn
.CommandText = "SELECT * FROM employee WHERE ID = " & FrmProfileGridView.MTProfile.SelectedRows(0).Cells(0).Value.ToString() & ""
End With

da.SelectCommand = cmd
dt15.Clear()
da15.Fill(dt15)
FrmProfileGridView.MTProfile.DataSource = dt15
cryRpt.Load("C:\empsys\WindowsApplication3\empprofile.rpt")
CrystalReportViewer1.SelectionFormula = " {employee.Emp_ID} = '" & FrmProfileGridView.MTProfile.SelectedCells(0).Value & "'"
CrystalReportViewer1.ReportSource = cryRpt
CrystalReportViewer1.Refresh()
cn.Close()
End Sub

i could not debug your code since di ko nakikita ang initialization mo ng da, cn, at dt15, but considering your code, ang error mo is: walang laman ang datatable mo.

da.selectcommand = cmd
dt15.clear ' <-- datatable
da.fill(dt15) '<--- put the fetched record to the datatable using the dataadapter

yourgrid.datasource = dt15

:)

*** EDIT *** please avoid the string concatenation in command text, instead use its parameter
.CommandText = "SELECT * FROM employee WHERE ID = " & FrmProfileGridView.MTProfile.SelectedRows(0).Cells(0).Value.ToString() & ""

.CommandText = "SELECT * FROM employee WHERE ID = @mySelectedId"
.Parameters.AddWithValue("@mySelectedId", FrmProfileGridView.MTProfile.SelectedRows(0).Cells(0).Value.ToString())
 
Last edited:
i could not debug your code since di ko nakikita ang initialization mo ng da, cn, at dt15, but considering your code, ang error mo is: walang laman ang datatable mo.

da.selectcommand = cmd
dt15.clear ' <-- datatable
da.fill(dt15) '<--- put the fetched record to the datatable using the dataadapter

yourgrid.datasource = dt15

:)

*** EDIT *** please avoid the string concatenation in command text, instead use its parameter
.CommandText = "SELECT * FROM employee WHERE ID = " & FrmProfileGridView.MTProfile.SelectedRows(0).Cells(0).Value.ToString() & ""

.CommandText = "SELECT * FROM employee WHERE ID = @mySelectedId"
.Parameters.AddWithValue("@mySelectedId", FrmProfileGridView.MTProfile.SelectedRows(0).Cells(0).Value.ToString())

TS! bale ganito na ginawa ko after nung path/location ng report inadd ko ito *cryRpt.SetDataSource(dt15). ang nagiging error naman is ganito:

View attachment 227326

pero kong di ko ilalagay yun nag-bbrowse naman yun ganito naman nagiging error sa report ko

View attachment 227327

by the way this is the output pala ng report ko bale dapat is selected lang yung lalabas na employee diyan

View attachment 227328
 

Attachments

  • Untitled.jpg
    Untitled.jpg
    460.7 KB · Views: 19
  • number.jpg
    number.jpg
    137 KB · Views: 15
  • report.jpg
    report.jpg
    298.7 KB · Views: 21
TS! bale ganito na ginawa ko after nung path/location ng report inadd ko ito *cryRpt.SetDataSource(dt15). ang nagiging error naman is ganito:

View attachment 1055140

pero kong di ko ilalagay yun nag-bbrowse naman yun ganito naman nagiging error sa report ko

View attachment 1055141

by the way this is the output pala ng report ko bale dapat is selected lang yung lalabas na employee diyan

View attachment 1055143

*** EDIT ***
dim mySet as new dataset
myset.add(dt15)

datasouce = myset
 
Last edited:
Back
Top Bottom