|
Well, you could do a couple of things. You could have an Enum in your project, like:
Namespace Munchkin
Public Enum Genders
Male
Female
End Enum
End Namespace
Then, you could declare your Gender field like:
Public Gender As Genders
And the only valid thing to put in it would be:
someCharacter.Gender = Genders.Male
You could do the same thing with levels, or you could throw an exception if a character's level is set below 1 or above 10:
Public Class Character
Private _level As Integer
Public Property Level() As Integer
Get
Return _level
End Get
Set(ByVal Value As Integer)
If Value < 1 Or Value > 10 Then
Throw New ApplicationException("Level must be between 1 and 10")
Else
_level = Value
End If
End Set
End Property
End Class
But guess what? Your Character is starting to sound more like a class than a structure...
What a piece of work is man, how noble in reason, how infinite in faculties, in form and moving how express and admirable . . . and yet to me, what is this quintessence of dust? -- Hamlet, Act II, Scene ii.
|
|
|
|
|
>But guess what? Your Character is starting to sound more like a class than a structure...
In that case, I must have misinterpreted your orginal advice; I had a project named Munchkin, a Class named Player, and a Structure named Character. It looked something like this:
Structure Character<br />
Public Name As String<br />
Public Gender As String<br />
Public Level As Integer<br />
End Structure
But I guess I should do the Class thing and the Structure thing seperately. Anyway, thanks for the help. I'm gonna try the Enum and Exception code now.
As I sit here, I contemplate the last words of Socrates: "I drank what?".
|
|
|
|
|
Although, on the other hand, you could produce a Class that acts like a Character factory. Anyway, glad I could lend a hand.
What a piece of work is man, how noble in reason, how infinite in faculties, in form and moving how express and admirable . . . and yet to me, what is this quintessence of dust? -- Hamlet, Act II, Scene ii.
|
|
|
|
|
I am working on some VB Script and am using an InputBox that accepts a password. When the user types in the password, I would like it to show up as *********
Any help doing this would be great. Here is some of the code:
strUserIn = InputBox("Enter Password")
if strUserIn <> "" then
Set fs = CreateObject("Scripting.FileSystemObject")
strFileName = fs.BuildPath(Wscript.ScriptFullName & "\..", "~userp.txt")
strFileName = fs.GetAbsolutePathName(strFileName)
Set ts = fs.OpenTextFile(strFileName, 2, True)
ts.WriteLine strUserIn
ts.Close
end if
|
|
|
|
|
VBScript and the Windows Script Host don't yet support a password-type input box yet. You'll have to use an external component of some kind to do this or make your code run in an HTML page and use an HTML password box. But, there are limitation on what your script can do inside a browser.
RageInTheMachine9532
|
|
|
|
|
High timer experts,
I have a problem very similar to the "Help clock generate" thread.
I want to control a stepper motor of an electrophoresis unit.
The Motor should be driven with (only) 250 hz.
The low precicion timers using the message que (windows.froms.timers)
are not usefull for this purpose (Instantly I wandered why the motor
does not perform all steps with the timer set to 50 Hz, but meassuring the
intervals using the system performancecounter revealed, that about every
10th interval is only 203 ticks long -- for what ever reason)
Looking for a solution, I came accross -Queue timers- which should be able to
deal with this problem. Unfortunately, I am not familiar with C programming language
and all the examples were written in C (e.g. here).
Is there a possibility to run such a timer from VB.net?
Thanks in advance
Armin
|
|
|
|
|
If my math is right, at 250Hz, you need to fire the event every 4 milliseconds. The timers that your finding all have 1 millisecond resolution. At that low an interval, the millisecond timers are not really that accurate. They can be off by as much as a millisecond when your app receives the notification.
I think that part of the problem is the priority that your process is running under. You might want to consider running your app and then, before you start the timer test, go into the Task Manager, click on the Processes tab, right-click on your app and bump the priority up to High or RealTime to see if the interval stabilizes for you.
RageInTheMachine9532
|
|
|
|
|
Hi All
I have started writing a program to get the crc32 of a file. I have this working fairly well. The only thing now is I need to get the crc32 of a complete folder and its contents and get an overall checksum for it, but I don't seem to be able to get it to work. If anyone can give some insight to this problem it would be great. Also I cannot get to display the file size of the file i am checking.
Thanks
|
|
|
|
|
You might want to show the code your using to get a CRC on a directory and its contents.
Are you looking to get the CRC on all the filenames? Or are you trying to get a combined CRC of all the files in the directory?
RageInTheMachine9532
|
|
|
|
|
I am trying to get a combined CRC for all the files. I am using the FastCRC library to try get the code to work. So far I can get the crc of a single file I have tried to code it to check the directory but it never works so I usually start from scratch again.
|
|
|
|
|
Code samples are important so we can see what your doing!
Your going to have to get the CRC of each file, one at a time. I downloaded the FastCRC library and according to the docs your can use FCRC32_CalculateFile to get the CRC of each file. This is a little pseudocode to illustrate:
' Assuming VB.NET
Dim checksum as Integer
FCRC32_Init()
For Each Filename in Directory
FCRC32_CalculateFile( checksum, Filename )
Next
MsgBox( FCRC32_LongToHex32( checksum, True ) )
RageInTheMachine9532
|
|
|
|
|
This is the main code that I was using
Private Sub cmdCRC32_click()
Dim checksum As Long
Dim buffer As Long
If txtFileInfo.Text = "" Then
MsgBox "PLEASE SELECT A FILE", vbExclamation, "No File Selected"
End If
'Calculate the CRC32 checksum and MD5 of a file
If FCRC32_CalculateFile(checksum, txtFileInfo.Text) = 0 Then
txtInfo.Text = txtFileInfo.Text & vbCrLf & _
"CRC32= " & FCRC_LongToHex32(checksum, True) & vbCrLf & _
"MD5=" & QHASH_FileHexDigest(MD5_ALGID, txtFileInfo.Text, True)
End If
End Sub
Thanks
|
|
|
|
|
So far, it looks good, though you can drop the declaration for 'buffer'. You'll never use it...
Now all you need to is to wrap this in code that goes thru a list of filenames and your all set. You can use the Dir() function to do this:
' Assuming VB.NET
' For VB6, change Integer type to Long
Dim iCheckSum As Integer
Dim strFilename As String
FCRC32_Init()
strFilename = Dir( startingPathAsString )
Do While strFilename <> ""
FCRC32_CalculateFile( iCheckSum, Filename )
strFilename = Dir()
Loop
MsgBox( "CRC32: " & FCRC32_LongToHex32( iCheckSum, True ) )
RageInTheMachine9532
|
|
|
|
|
I'm still having huge problems using the dir function. Is there a sample of code i could get
|
|
|
|
|
You'll have to post what you have so we can see what your doing. The only code example I have is in my previous post.
RageInTheMachine9532
|
|
|
|
|
can u plz. tell me wots CRC32
rIsHaBh
|
|
|
|
|
It's a 32 bit Cyclic Redundancy Check. Its used to give a block of data a value that represent an error check. The block of data is transmitted with it's CRC value, then the receiver gets the block, performs a CRC calculation on it and compares that value with the CRC that was transmitted with the block of data. If the two don't match, there was problem with the transmission.
RageInTheMachine9532
|
|
|
|
|
CRC stands for Cyclic Redundency Check. Where I work we use it to check .iso files transfered over the network to make sure that it is the same. If anything happened to it in transfer there would be a difference. So if the CRC32 is the same then the file is the same. It can be used to check all the files on a cd also, so if any file changed in creating a cd the CRC32 checksum would be different than that of the master disc.
|
|
|
|
|
Thank u buddies!!
rIsHaBh
|
|
|
|
|
i'm srying to read a table from a sql database. i'm using a sqldataadapter, what code should i put in the page load for this to work
|
|
|
|
|
Hi CodeProject Champs
I want to deploy Crystal Report with my software. I got registered on the site www.crystaldecisions.com/net/licensing. After deployment it was giving error "Invalid Keycode". When I registered they send me a pdf named net_distribution_license.pdf file. But it does not have any keycode. How shud i proceed? From where to get the key code for crystal report.
thanks
Be Humble in Victory and Strong in Defeat. -Het
|
|
|
|
|
Hi,
I have been added a web reference. VB.NET has been created a proxy class in my project. But I need to declare prefix for an element. How can I add prefix into an element such as below by VB.NET?
I want to following form;
<RFC_GET_TRUSTED_SYSTEM_ID.Response xmlns="urn:sap-com:document:sap:rfc:functions">
To following form;
<x:RFC_GET_TRUSTED_SYSTEM_ID.Response x:xmlns="urn:sap-com:document:sap:rfc:functions">
Thank you
Orkun GEDiK
|
|
|
|
|
hi,
her problem of M-DAC is really not working out, please please please help her out.
Thanks to all for reading
Be Humble in Victory and Strong in Defeat. -Het
|
|
|
|
|
'//Connecting to sqlserver thru ADO
Dim sConnectionstring As String
Dim rst As New ADODB.Recordset 'will hold records returned
Dim com As New ADODB.Command 'will pass command to sql server
Dim cn As New ADODB.Connection 'our database connection object
sConnectionstring = "Uid=Yourusername; pwd=Yourpassword;" & _
"InitialCatalog=Yourdatabase;" & _
"Data Provider=SQLOLEDB; provider=MSDATASHAPE;" & _
"Server=Your-server-if-any;"
cCnn.ConnectionString = sVarConnectionString
cCnn.Open
With com
.ActiveConnection = cn
.CommandText = "SELECT * FROM your-table"
.CommandTimeout = 0 '//don't time-out
.CommandType = adCmdText '//exec the text
End With
rstGP.Open com '//open the recordset
'//accessing the data in rst
If Not rst.BOF And Not rst.EOF Then rst.MoveFirst
While (Not rst.EOF)
MsgBox "Field1 = " & rst!Field1 '//Field1 is a colum in the table
MsgBox "Field2 = " & rst!Field2 '//Field2 is a colum in the table
MsgBox "Field3 = " & rst!Field3
MsgBox "Fieldn = " & rst!Fieldn
rst.MoveNext
Wend
'//Creating a table..
CREATE TABLE
[ database_name.[ owner ] . | owner. ] table_name
( { < column_definition >
| column_name AS computed_column_expression
| < table_constraint > ::= [ CONSTRAINT constraint_name ] }
| [ { PRIMARY KEY | UNIQUE } [ ,...n ]
)
e.g. assume my database is called db1 - i can create table tb1 with
2 columns col1 and col2
CREATE TABLE
db1 tb1
(
col1 AS INT,
col2 AS VARCHAR(100) NOT null
)
'//xml
Don know much about xml..
1fm1fu
|
|
|
|
|
Hello,
I programmed a click event handler for a button on a worksheet. In this handler I wanted to change some cells. But when the handler changed the first cell it aborted directly after the comand.
Here's my code:
This is the event handler itself, it is calling another function that is doing the work:
Private Sub bReorgWorkTime_Click()
ReorgWorkTime bReorgWorkTime.Parent
End Sub
Public Function ReorgWorkTime(xButtonWorksheet As Worksheet)
Dim iDay As Integer
Dim xWorkTime As Variant
Dim xReorgedTime As Variant
Dim dWorkTime As Double
Dim bOldEventsEnabled As Boolean
iDay = ROW_DAY_1
bOldEventsEnabled = Application.EnableEvents
Application.EnableEvents = False
' Fill in all days without over times:
While (iDay <= ROW_DAY_31)
xWorkTime = xButtonWorksheet.Cells(iDay, COL_WORKED_TIME)
If (IsNumeric(xWorkTime) And Not IsEmpty(xWorkTime)) Then
dWorkTime = xWorkTime
xButtonWorksheet.Cells(iDay, COL_REORGED_TIME) = dWorkTime
' Aborts here
Else
xButtonWorksheet.Cells(iDay, COL_REORGED_TIME) = ""
' or here
End If
iDay = iDay + 1
Wend
Application.EnableEvents = bOldEventsEnabled
End Function
Believing the debugger the "iDay = iDay + 1" line isn't even reached!
I use Excel 2002 SP-1 German
|
|
|
|