|
Is this VB6 ? It looks like a bunch of p/invoke code. go to www.pinvoke.net to find out how to do the pinvoke part, and the rest is trivial.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Does anyone knows how to detect memory card/storage card from a smart device using vb.net CF ? The challenge is because there are many brands and versions of PDA, means that the naming of the storage device might be different as well. I want to get the drive name of the storage device. Thanks in advance
i wish to learn more from this forum
|
|
|
|
|
is there a way to check the remaining free space availabe on the Hard Disk and notify the user of that?
I mean how can i display a popup msg to the user when the free remaining size reaches 90% for example?
Regards
Ramy
|
|
|
|
|
|
Try this. In this example you will need one button and 3 textboxes.Hope this helps
Declareations
Inherits System.Windows.Forms.Form<br />
Private Declare Function GetDiskFreeSpaceEx _<br />
Lib "kernel32" _<br />
Alias "GetDiskFreeSpaceExA" _<br />
(ByVal lpDirectoryName As String, _<br />
ByRef lpFreeBytesAvailableToCaller As Long, _<br />
ByRef lpTotalNumberOfBytes As Long, _<br />
ByRef lpTotalNumberOfFreeBytes As Long) As Long<br />
<br />
<br />
<br />
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click<br />
TextBox1.Text = GetFreeSpace("C:\")<br />
TextBox2.Text = GetTotalSpace("C:\")<br />
GetPercentageFree()<br />
If TextBox3.Text < 36 Then<br />
MsgBox("You are running out of space")<br />
End If<br />
End Sub<br />
Public Function GetFreeSpace(ByVal Drive As String) As Long<br />
'returns free space in MB, formatted to two decimal places<br />
'e.g., msgbox("Free Space on C: "& GetFreeSpace("C:\") & "MB")<br />
<br />
Dim lBytesTotal, lFreeBytes, lFreeBytesAvailable As Long<br />
<br />
Dim iAns As Long<br />
<br />
iAns = GetDiskFreeSpaceEx(Drive, lFreeBytesAvailable, _<br />
lBytesTotal, lFreeBytes)<br />
If ians > 0 Then<br />
<br />
Return BytesToMegabytes(lFreeBytes)<br />
Else<br />
Throw New Exception("Invalid or unreadable drive")<br />
End If<br />
<br />
<br />
End Function<br />
<br />
<br />
Public Function GetTotalSpace(ByVal Drive As String) As String<br />
'returns total space in MB, formatted to two decimal places<br />
'e.g., msgbox("Free Space on C: "& GetTotalSpace("C:\") & "MB")<br />
<br />
Dim lBytesTotal, lFreeBytes, lFreeBytesAvailable As Long<br />
<br />
Dim iAns As Long<br />
<br />
iAns = GetDiskFreeSpaceEx(Drive, lFreeBytesAvailable, _<br />
lBytesTotal, lFreeBytes)<br />
If iAns > 0 Then<br />
<br />
Return BytesToMegabytes(lBytesTotal)<br />
Else<br />
Throw New Exception("Invalid or unreadable drive")<br />
End If<br />
End Function<br />
<br />
Private Function BytesToMegabytes(ByVal Bytes As Long) _<br />
As Long<br />
<br />
<br />
Dim dblAns As Double<br />
dblAns = (Bytes / 1024) / 1024<br />
BytesToMegabytes = Format(dblAns, "###,###,##0.00")<br />
<br />
End Function<br />
Public Function GetPercentageFree()<br />
Dim free As Integer<br />
Dim total As Integer<br />
Dim percent As Integer<br />
free = GetFreeSpace("C:\")<br />
total = GetTotalSpace("C:\")<br />
<br />
percent = (free / total) * 100<br />
TextBox3.Text = percent<br />
End Function
|
|
|
|
|
Dim strPath As String = "C:\Video"<br />
Dim strSearch As String = ".avi"<br />
<br />
<br />
For Each strFile As String In My.Computer.FileSystem.GetFiles(strPath, FileIO.SearchOption.SearchTopLevelOnly, strSearch)<br />
<br />
ListBox1.Items.Add(My.Computer.FileSystem.GetName(strFile))<br />
Next
Can somebody tells me why it won't populate my listbox with avi files in C:\Video? Can somebody fix the code here?
|
|
|
|
|
What happens when you step through the code ? Should the search string be *.avi ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Sorry I had to redesign some of your code but it should work.
Dim strPath() As String <br />
Dim strSearch As String <br />
strPath = IO.Directory.GetFiles("C:\video")<br />
<br />
For Each strSearch In strPath<br />
If InStr(strSearch, ".avi", CompareMethod.Text) Then<br />
ListBox1.Items.Add(strSearch)<br />
End If<br />
Next
Tell me if it does
Hope this helps
|
|
|
|
|
Sorry guys for the late reply, actually the code I pasted before does work. There was something wrong with my listbox properties so that the files found isn't visible on the listbox. I deleted the listbox and create a new one and now it runs fine Sorry again..
Thanks anyway
|
|
|
|
|
Dear all,
Please tell me hoew can i open a new form from the previous form on clicking the button????
Regards
Pari
pari
|
|
|
|
|
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click<br />
<br />
Dim frm2 As New Form2<br />
frm2.Showdialog() <br />
end sub
Where button1 is the button that you click on to show the new form.
Where form2 is the name of the form you want to show.
Hope this helps
-- modified at 3:16 Monday 30th April, 2007
|
|
|
|
|
Please, never do this. If you call Show and not ShowDialog, the form should be a member variable.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Christian Graus wrote: If you call Show and not ShowDialog, the form should be a member variable.
Oops my mistake.
I should of known better, I usually do use showdialog instead of show.
The code works though.
I'll just change it.
|
|
|
|
|
If you use ShowDialog, you also MUST call Dispose on the object when your done with the form. A resource leak will result if you don't.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
Dear all, i'm an ASp.net developer but i'm workin on a desktop application
There is a requirement that is to open only one executable of the application and if the user tries to open another instance the application returns an error message
So how can i know that there is an instance already running?
One of the thoughts was to create a state variable saved in a text file or xml file but u cann't manage it 100% because maybe the OS restarted or the user closes the application by killing the process... So i think there is a better way by checking running prcesses in the memory.
Any key how can i implement that?
P.S. I'm using VB script on VS.net 2003
Best Regards
3ala2
|
|
|
|
|
I found the solution
It's by importing: System.Diagnostics
declaring a process array and use the GetProcess method
then looping throught the array and check if the process already exists...
Thanks anyway
Best Regards
3ala2
|
|
|
|
|
Try this :-
Dim currentProcess As Process = Process.GetCurrentProcess()<br />
Dim allProcesses() As Process = Process.GetProcessesByName(currentProcess.ProcessName)<br />
<br />
If allProcesses.Length > 1 Then<br />
Me.Opacity = 0.5<br />
MessageBox.Show("Program already running. This session will close")<br />
Application.Exit()<br />
End If
Steve Jowett
-------------------------
Sometimes a man who deserves to be looked down upon because he is a fool, is only despised only because he is an 'I.T. Consultant'
|
|
|
|
|
Thank u very much
I tired it and it works great
Thanx again
Best Regards
3ala2
|
|
|
|
|
I am developing a project to import a CSV format file and iinserting the data to Access Database.
After importing the data to a datagridview, i am inserting the data in datagridview to Database using a dataset(ds).
The insertion has to take place in two different tables (Candidate and Test).
The below code is what i am using for to serve the purpose.
'Updating Candidate table working properly
Private Sub ibt()
Dim i, id As Integer
Try
strSQL = "select ECCMID from Candidate where ECCMID=(select max(ECCMID) from Candidate)"
cnSQL = New OleDbConnection(ConnectionString)
cnSQL.Open()
cmSQL = New OleDbCommand(strSQL, cnSQL)
drSQL = cmSQL.ExecuteReader()
If drSQL.Read() Then
id = drSQL.Item("ECCMID") + 1
ph = id
Else
id = 7001
ph = id
End If
For i = 0 To ((ds.Tables("CInfo").Rows.Count) - 1)
strSQL = "insert into Candidate(ECCMID,CFName,CMName,CLName,MA1,MA2,MA3,City,State,Zipcode,Country) values(" & id & ",'" & ds.Tables("CInfo").Rows(i).ItemArray.GetValue(0) & "','" & ds.Tables("CInfo").Rows(i).ItemArray.GetValue(1) & "','" & ds.Tables("CInfo").Rows(i).ItemArray.GetValue(2) & "','" & ds.Tables("CInfo").Rows(i).ItemArray.GetValue(3) & "','" & ds.Tables("CInfo").Rows(i).ItemArray.GetValue(4) & "','" & ds.Tables("CInfo").Rows(i).ItemArray.GetValue(5) & "','" & ds.Tables("CInfo").Rows(i).ItemArray.GetValue(6) & "','" & ds.Tables("CInfo").Rows(i).ItemArray.GetValue(7) & "','" & ds.Tables("CInfo").Rows(i).ItemArray.GetValue(8) & "','" & ds.Tables("CInfo").Rows(i).ItemArray.GetValue(9) & "')"
cnSQL = New OleDbConnection(ConnectionString)
cnSQL.Open()
cmSQL = New OleDbCommand(strSQL, cnSQL)
cmSQL.ExecuteNonQuery()
id = id + 1
Next
drSQL.Close()
cnSQL.Close()
cmSQL.Dispose()
Catch Exp As OleDbException
MsgBox(Exp.Message, MsgBoxStyle.Critical, "Oledb Error")
Catch Exp As Exception
MsgBox(Exp.Message, MsgBoxStyle.Critical, "General Error")
End Try
End Sub
'Updating Test table its generating an error as "Unspecified error" after certain records are inserted. The error can struck at 2 record or at 90th record or at any point.
Private Sub ibt1()
Dim i, id1 As Integer
Dim s As String = "Null"
id1 = ph
Try
For i = 0 To ((ds.Tables("CInfo").Rows.Count) - 1)
s = IIf(IsDBNull(ds.Tables("CInfo").Rows(i).ItemArray.GetValue(11)), Nothing, ds.Tables("CInfo").Rows(i).ItemArray.GetValue(11))
strSQL = "insert into Test(ECCMID,TestID,Title,Series,TestD,Result) values(" & id1 & "," & 1 & ",'" & ds.Tables("CInfo").Rows(i).ItemArray.GetValue(10) & "','" & CInt(s) & "','" & ds.Tables("CInfo").Rows(i).ItemArray.GetValue(12) & "','" & ds.Tables("CInfo").Rows(i).ItemArray.GetValue(13) & "')"
cnSQL = New OleDbConnection(ConnectionString)
cnSQL.Open()
cmSQL = New OleDbCommand(strSQL, cnSQL)
cmSQL.ExecuteNonQuery()
id1 = id1 + 1
Next
Main.StatusLabel1.Text = "Records are successfully inserted"
MsgBox("The * file data has been imported to the database", MsgBoxStyle.Information, "Information")
drSQL.Close()
cnSQL.Close()
cmSQL.Dispose()
Catch Exp As OleDbException
MsgBox(Exp.Message, MsgBoxStyle.Critical, "Oledb Error")
Catch Exp As Exception
MsgBox(Exp.Message, MsgBoxStyle.Critical, "General Error")
End Try
End Sub
The problem is in the second fuction.
While Updating Test table its generating an error as "Unspecified error" after certain records are inserted. The error can struck at 2 record or at 90th record or at any point, no specific location.
Can any body help me with it, i just need a clue why the error is generated, Any problem with the code?
Plz help...
Jats
|
|
|
|
|
No-one is going to read all this code. Odds are, the problem is with the data, at the specific rows that are blowing up. Your code is at risk of SQL injections, perhaps one is happening by accident ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Thankx for the help!!!
But i found the problem and solved it.
Thankx anyway!!!
Jats
|
|
|
|
|
And does this solution fix the SQL Injection Attack problem too?
|
|
|
|
|
How to read the volume label of drive X? For example, if the drive D has label "Linux", the function would return this name when called with parameter "D:".
|
|
|
|
|
|
Is there a better way to run a function every hour than enable a timer with tick value "3600000"? The problem is that when my application is running and this timer is enabled, Windows XP won't shutdown.
|
|
|
|
|