|
I want to add a section in my vb.net application to ask the client if they want to format a diskette or not. If they answer yes, go ahead and format a diskette in drive a:.
Does anyone have some code in Vb that will format a diskette?
Any Help is Appreciated
|
|
|
|
|
You could try using the Windows API SHFormatDrive() function -- here's a class that wraps it:
Public Class ShellUtilities
Public Declare Unicode Function SHFormatDrive _
Lib "Shell32.dll" _
(ByVal hwnd As IntPtr, _
ByVal iDrive As Int32, _
ByVal iFormatID As Int32, _
ByVal iOptions As Int32) As Int64
Public Const SHFD_CAPACITY_DEFAULT = 0 'default drive capacity
Public Const SHFMT_OPT_FULL = 1
Public Const SHFMT_OPT_SYSONLY = 2
Public Shared Sub FormatDrive(ByVal dialogOwner As IntPtr, ByVal iDrive As Int32)
SHFormatDrive(dialogOwner, iDrive, SHFD_CAPACITY_DEFAULT, SHFMT_OPT_FULL)
End Sub
End Class
And here's an example of calling it from a windows form button click:
Const A_Drive = 0
Const B_Drive = 1
Const C_Drive = 2
' ... etc ...
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ShellUtilities.FormatDrive(Me.Handle, A_Drive)
End Sub
|
|
|
|
|
Try this:
Const SHFMT_ID_DEFAULT = -1
Const SHFMT_OPT_FULL = 1
Const SHFMT_OPT_SYSONLY = 2
Const SHFMT_ERROR = -1 ' Error on last format, drive may be formatable
Const SHFMT_CANCEL = -2 ' Last format was canceled
Const SHFMT_NOFORMAT = -3 ' Drive is not formatable
' SHFormatDrive takes 4 parameters:
' hWnd The handle to the window that will be the dialogs parent window.
' Drive The drive number to format, 0 is A:, 1 is B:, 2 is C:, ...
' fmtID Must always be SHFMT_ID_DEFAULT, or the value ????.
' options Opitons.
Private Declare Function SHFormatDrive Lib "shell32" ( _
ByVal hWnd As IntPtr, _
ByVal Drive As Integer, _
ByVal fmtID As Integer, _
ByVal options As Integer) _
As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim iDrive As Integer
Dim rc As Integer
iDrive = 0
rc = SHFormatDrive(Me.Handle, iDrive, 0, 0)
Select Case rc
Case SHFMT_ERROR
MsgBox("Format failed, user pressed CLOSE")
Case SHFMT_CANCEL
MsgBox("Format cancelled - user hit CLOSE")
Case SHFMT_NOFORMAT
MsgBox("Unable to format this disk drive")
Case Else
MsgBox("Disk was formatted successfully and returned: " & rc)
End Select
End Sub
This will show the format dialog that you see when you do a format from the Explorer Shell. The format won't start until the user presses OK.
RageInTheMachine9532
|
|
|
|
|
Thank you very much for your feedback. I used the code that everyone submitted and it worked great!!
Is there a way to pass the Label that you want to use when formatting the diskette.
I found the SHFormatDrive documentation on MSDN, but I really don't see a way to pass a Label in.
Thanks again for the help,
Kevin
Lost in the vast sea of .NET
|
|
|
|
|
You can't pass that information to SHFormatDrive, but you can set the volume label after the disk is successfully formatted. You can use SetVolumeLabel, declared in kernel32, by passing in the root path of the drive, like A:\, and the name you want:
Private Declare Function SetVolumeLabel Lib "kernel32" _
Alias "SetVolumeLabelA" ( _
ByVal rootPath As String, _
ByVal newLabel As String) _
As Integer
Dim rc as Integer
rc = SetVolumeLabel( "A:\", "LabelTest" )
RageInTheMachine9532
|
|
|
|
|
Hy,
I want to make an apllication in vb.net that send's through the POST method the user and pass to the yahoo page and returns me into a text box the link to my inbox.
Any ideas.
Thanks.
|
|
|
|
|
Why should i use subclassing? I am not sure what it is for or how it is used. do you know where i can find an article about this subject?
Thnx,
Grtz,
Guus
|
|
|
|
|
Hi there. Subclassing is the act of deriving a new class by inheriting from an existing class. You would do this if you wanted to take advantage of functionality in the base class and add functionality of your own. For example, let's say you want a text box for your windows forms application, but one that accepts only numbers and ignores other characters typed from the keyboard. In most ways, you want your text box to behave just like a regular text box; you just want the additional functionality that limits keyboard entry to numbers only. You could create a subclass of the TextBox class by inheriting it, then override keyboard handling methods to insure that only numbers are allowed.
|
|
|
|
|
Well the subject says it all.
I believe that every object has a hWnd and using this hWnd you can color the background of a treeview or do all sorts of thing. Do you know where i can find an article about this?
Thnx,
Grtz,
Guus
|
|
|
|
|
gpa2000 wrote:
I believe that every object has a hWnd
Not true. every Window has a Window Handle. Individual controls are also windows and have a window handle. But not every element you see on the screen or every object in memory has a Window Handle.
gpa2000 wrote:
using this hWnd you can color the background of a treeview or do all sorts of thing
Uhhh...not exactly. The hWnd is the identifier for a Window that you can use to talk to the Window or other functions that take a hWnd as an input parameter. The Win32 API is FULL of funtions that use hWnd and not just for modifiying control properties. There isn't any one article that covers all the uses for Window Handles, but you can start here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/windows.asp[^]
RageInTheMachine9532
|
|
|
|
|
hello
i wish to know the coding
for the button
that perform opening either Internet Explore or Netscape
to a web address
i hope it wont be a trouble
thank you
Gary
|
|
|
|
|
In VB:
'<br />
' Procedure voor het opstarten van de default browser met een URL<br />
'<br />
' Zie Q224816, Q174156 voor meer informatie<br />
'<br />
Public Sub StartDefaultBrowser(ByVal strUrl As String)<br />
Dim lngReturnValue As Long<br />
<br />
lngReturnValue = ShellExecute(0, _<br />
"open", _<br />
strUrl, _<br />
0, _<br />
0, _<br />
SW_SHOWNORMAL)<br />
' Returnvalue <= 32 means error<br />
If (lngReturnValue <= 32) Then<br />
Err.Raise ERR_WARNING, FormatErrSource(MODULENAME, "CheckFields"), "Can't start default internet browser (" & CStr(lngReturnValue) & ")"<br />
End If<br />
<br />
End Sub
Grtz,
Guus
|
|
|
|
|
|
Can someone tell me how to print the text at the center of the paper?
i am using a receipt print with a maximum of 40 characters per line
Proper Planning is way to success
|
|
|
|
|
Since you know the width of the printer you pad the beginning of the string with spaces. Take the length of the line you want to print away from the width of the printer, then divide that difference by 2 to get the number of spaces to add on both sides of the test you want to print, but only add it to the beginning of the text:
Dim sText As String = "Text to print Centered"
Dim iPad As Integer
iPad = ( 40 - sText.Length ) / 2
sText = New String( Chr(32), iPad ) & sText
RageInTheMachine9532
|
|
|
|
|
New string is an unexperted identified. so how??
Proper Planning is way to success
|
|
|
|
|
Are you using VB6 or VB.NET?
The code sample works as advertised on VB.NET.
The equivelent code in VB6 would be this:
Dim sText As String
Dim iPad As Long
sText = "Text to print Centered"
iPad = ( 40 - Len(sText) ) / 2
sText = String$( iPad, 32 ) & sText
RageInTheMachine9532
|
|
|
|
|
Writing code using VB.net (aspx file)~ script assignment statement: set UserData = request.form("UserData") yields a compile error ~ 'Let' and 'Set' assignment statements no longer supported. Is there a substitute assignment statement that will work instead of 'Set' ?
Many thanks!
Reed Eichner
reichner@satx.rr.com
|
|
|
|
|
Yeah:
Dim UserData As String
UserData = Request.Form.Item("UserData")
RageInTheMachine9532
|
|
|
|
|
Hello,
Is there a way to create an entire Access database (I know what tables and the relationships needed between the tables) using VB code? For instance, if a user clicked on a "Create Plan" icon, the following database would be created in the back end:
Database: Census
Tables:
Client
Plan
Employees
Contacts
If you know of references you could direct me to in order to learn more about this, it would be greatly appreciated.
Thanks so much!
Vi
|
|
|
|
|
There are ways to do this. Are you using VB6 or .NET?
|
|
|
|
|
Hi Mike,
I forgot to mention that I'm using VB.net . I'm a new user and have just gone through my first book Visual Basic.Net Step by Step. I'm trying to create a utility for use at work and have no idea where to begin. Any ideas / help would be greatly appreciated.
Thanks so much!
Vi
|
|
|
|
|
Hi Vi. You know, most beginners start with "Hello World" instead of "Create Access Database from Scratch"
One way to accomplish what you're describing is through the ADOX library. Here's a link to MSDN documentation introducing ADOX:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/admscadoxfundamentals.asp[^]
In a nutshell, the ADOX Catalog object's Create() method will let you create the .mdb file. Then you can use a standard ADO.NET OleDbConnection object to connect to the new database file, and an ADO.NET OleDbCommand object to execute sql statements against the connection. Using OleDbCommand 's ExecuteNonQuery() method will let you issue statements like "Create Table xxx ..." to create your tables. Alternatively, you could use ADOX's Table object to accomplish the same task.
ADOX is a COM library, not a .NET library, meaning that you have to use Interop techniques to use the ADOX objects in your .NET code. This isn't difficult, and there are many articles available on the subject of COM Interop. This article shows an example of using Visual Studio to make the proper references to the COM ADOX library:
http://www.tek-tips.com/gfaqs.cfm/lev2/4/lev3/32/pid/796/fid/3888[^]
This article (right here on CodeProject) goes more in depth into the concept of Interop. Its fairly long, but toward the bottom are ADOX examples that are directly relevant to the task you're working on -
http://codeproject.com/books/186100558x_16.asp[^]
I hope this gives you something you can work with.
--mike
|
|
|
|
|
Excellent! Thank you so much Mike for taking the time to post this. I will most definitely do some digging.
|
|
|
|
|
Hello, My name is jason.
I am trying to write a program that will track the times and the dates that an employee has worked. I know how to hard code it but, it is the gui that i am having a problem with. Here are my main problems. When the program starts i would like a password screen to appear, where the user or the manager enters her/his password. This part I have accomplished, the password screen. I have placed 9 buttons, when the user clicks on the buttons i record or add to a string, and when the user hits okay, i read the finished string and see if there is an employee. My problem is this, I need to have to different windows, one for a manager, and another for a employee. Meaning, if a manager comes along, types his password, i would like a window appearing where he has the option of looking how has clocked in, how many employees are currently working, total hours ans so forth. When a employee comes along, enters his/her password, i would like them to see when they have started, or if they have not punched in, a punch in button, or a punch out button and so forth..
If anyone could help me out, or give me advice on how to create those two different windows and how to interact or how to dynamilcly pop up those two windows depending on who is entering a password, i would be sooooo happy.
you can email me at jdogan@hotmail.com
none
|
|
|
|