snarfblam
Leaders-
Posts
2156 -
Joined
-
Last visited
-
Days Won
2
Content Type
Profiles
Forums
Blogs
Events
Articles
Resources
Downloads
Gallery
Everything posted by snarfblam
-
I did this in VB6 once. The algorithm went like this... Function EvaluateExpression() As Double Result = EvaluateNumber() If next character = "+" then Result += EvaluateTerm() If next character = "-" then Result -= EvaluateTerm() End Function Function EvaluateTerm() As Double Result = EvaluateExponent() If next character = "*" then Result *= EvaluateExponent() If next character = "/" then Result /= EvaluateExponent() End Function Function EvaluateExponent() As Double Result = ParseDouble() If next character = "^" then Result ^= ParseDouble() End Function Function ParseDouble() As Double Seek through the string, extract the next number, and Integer.Parse it Return what we parsed OR if we run into an opening parenthesis "(" then we jump back in to EvaluateExpression Voila! Parentheses resolved through recursion End Function [/Code] [Edit]This doesn't involve a stack and the order of operations will happen like magic. Plus it will handle parentheses. You just need to keep a "pointer" somewhere in the class that keeps track of what character you are looking at as you seek through the string.[/Edit] btw, something I am working on now... a class that accepts an algebraic expression (containing variables) and instead of evaluating the expression immediately it breaks it down into a list of simple tokenized commands (think p-code... vb6) only with real simple commands like byte code (think msil)... as in "put this number on the stack" and "add the top two numbers on the stack and store the result on the stack". This can process batches of numbers more quickly for the sake of graphing or processing tables of numbers for statistical or scientific purposes.
-
So... you want to multiply the second & fourth digits by two, and add them with eachother and the first and third digit, and then verify that the fifth digit is equal to the last digit in the sum of other digits... is that what you want? If so then here is an example... Function ValidateString(ByVal S As String) As Boolean Dim Values(4) As Integer Dim Chars As Char() = S.ToCharArray 'You could just use the .substring function, but when I deal with characters ' i prefer to deal with Chars 'You might want to test that s.Length is valid For i As Integer = 0 To 4 'Extract Values Values(i) = AscW(Chars(i)) - &H30 'Yes... you could also use Integer.Parse 'My apologies to those that I might have offended by using functions from Microsoft.VisualBasic ' but VB doesn't treat chars as numbers the way C languages do Next Dim Sum As Integer = (Values(0) + Values(1) * 2 + Values(2) + Values(3) * 2) Return Sum Mod 10 = Values(4) End Function That last line might confuse you but what it does is (Sum Mod 10) equals the last digit in your sum. This is compared to your last digit (Values(4)), your checksum of sorts. The function returns whether they are equal or not, and hence whether the string of digits is valid or not.
-
Are you showing one record at a time in one textbox at a time? Anyways, I would recommend using the System.Drawing.Graphics.MeasureString function to see if the text will fit in the box, and if it doesnt then... you can try decreasing the fontsize by one until it fits (provided that you have a point at which it will give up; it would be pointless to show your data at a size 1 font and this method may be somewhat error prone). If you absolutely can not increase the size of your textbox perhaps you can set the record text to a tool tip so that the user can place the mouse over the textbox and the record will pop up in a tooltip.
-
Huh, I actually thought that they had done away with goto like they did gosub. Structured programming has nearly rendered it useless anyways but... Put a "Do" on the line you want to go to. Put a "Loop While <Condition>" on the line that you want to go back to. If <Condition> evaluates to True then the program will branch to the line after the "Do". I beleive in your case this performs the exact same function Goto would for you.
-
Just as the "Index > 0" condition tests if the selected item's index is greater than that of the first item, the move down function should test if the selected index is less than that of the last item. Keep in mind that you also need to either test if the index = -1 or if Swap is Nothing, either of which will indicate that nothing is selected. So... here. Have some code. Sub MoveSelectedItemDown(ByVal Box As ListBox) Dim Index As Integer = Box.SelectedIndex 'Index of selected item Dim Swap As Object = Box.SelectedItem 'Selected Item If (Index <> -1) AndAlso (Index + 1 < Box.Items.Count) Then Box.Items.RemoveAt(Index) 'Remove it Box.Items.Insert(Index + 1, Swap) 'Add it back in one spot up Box.SelectedItem = Swap 'Keep this item selected End If End Sub
-
I hope i am not missing something particularly obvious but I have installed the managed directx sdk (debug) on my computer even restarted and it does not appear in the list of managed components when I try to add a reference. Last time I installed managed directx i didnt have this problem. Kinda hard to program for directx w/o the reference.
-
Ideally if the selected item is already at the top you want to disable the "move up" button since it cant be moved up. If you prefer not to, then replace the line "If Not (Swap Is Nothing) Then" with "If Index > 0 Then". This will only move items with an index 1 or higher (i.e. the second or higher item on the list).
-
Nothing wrong with windows apis... do the vb6 and .net runtimes, mfc, as well as most programs not eventually come down to windows apis (not an assertion, i honestly dont know)?
-
First of all, a Select Case would be much better suited for this. It will run faster (though I doubt this will be an issue) and require less code. Dim WeaponPower As Integer Select Case comboWeapon.Text Case "Fists Only" WeaponPower = 0 Case "Bronze Long Sword" WeaponPower = 7 Case "Adam Long Sword" Then WeaponPower = 32 End Select If you have a substantial amount of weapons consider doing it like this: Dim Weapons As String() = {"Fists Only","Bronze Long Sword","Adam Long Sword"} Dim Power As Integer() = {0, 7, 32} Function PowerOfWeapon(Weapon As String) Dim i As Integer Do While i < Weapons.Length 'Until we reach the end of the weapon list If Weapons(I) = Weapon 'If we have a match return the weapons power Return Power(i) EndIf i += 1 Loop 'At this point there is no match. You could 'just return zero, or throw an exception. End Function The second method creates two lists in the form of arrays: a list of weapons and a list of their respective strength. The function searches the list of weapons until a match is found and returns the respective power.
-
Assuming you are using vb... Sub MoveSelectedItemUp(ByVal Box As ListBox) Dim Index As Integer = Box.SelectedIndex 'Index of selected item Dim Swap As Object = Box.SelectedItem 'Selected Item If Not (Swap Is Nothing) Then 'If something is selected... Box.Items.RemoveAt(Index) 'Remove it Box.Items.Insert(Index - 1, Swap) 'Add it back in one spot up Box.SelectedItem = Swap 'Keep this item selected End If End Sub [/Code] If you are c# then... this is PROBABLY WRONG but you can get the jist of it [Code] void MoveSelectedItemUp(ListBox Box) { int Index = Box.SelectedIndex; //Selected Index object Swap = Box.SelectedItem; //Selected Item If (Index == -1) { //If something is selected... Box.Items.RemoveAt(Index); //Remove it Box.Items.Insert(Index - 1, Swap); //Add it back in one spot up Box.SelectedItem = Swap; //Keep this item selected } } [/Code]
-
You need to understand the difference between a number (i.e. 1.423412) and an expression (5+20*100). Yes, you can convert numbers to strings and vice-versa. You can not convert expressions in the form of strings into numbers with any sort of casting. You will find yourself dealing with an invalid-cast exception if you try this. The .Net framework does not have a calculator class built into it (although this would be an exceptionally useful class). You can write your own (not easy for someone new to vb) or search google for a solutions. (Or persue the msscript control solution suggested. A google search will be sure to turn up the code and explination. Search for ["MS Script Control" evaluate expression]).
-
Determining common start menu/startup folder
snarfblam replied to snarfblam's topic in Directory / File IO / Registry
...hence the use of Environment.GetFolder and the existance of this thread. Is there anyway to determine the path of %ALLUSERSPROFILE%? I can get the path for common program files and common application data. I need to common start menu. Are these all guaranteed to be in that same parent directory? I know that each users app data and start menu and program files are NOT guaranteed to be in the same folder (you can easily change the locations of these folders with Tweak UI). -
The System.Environment.GetFolderPath() function can be used to get a user's startup or start menu folder, for example: C:\Windows\Documents and Settings\Freddie\StartMenu -or - C:\Windows\Profiles\Frank\StartMenu\Startup How can you get the common start menu or startup folder? As in... C:\Windows\Documents and Settings\All Users\StartMenu (I already checked... There is no option for common start menu or common documents and settings or common startup.)
-
As long as the transparent color is set properly on your imagelist control you should be fine.
-
You can not modify single aspects of a font, i.e. size, style, etc. You must assign the .Font property to a new instance of the Font class. For example: Me.Font = New Font(Me.Font, FontStyle.Underline) This will set the label's font to a new font based on the label's current font with the style changed to underline, which is what I beleive you want to do.
-
Is there a way to distort an image using GDI+? Version 1.1 of the .Net Framework hasn't implemented DrawImage(Image, Point()) for four points. That is, you can specify three points to define a parallelogram that skews the image, but if you specify four points for full distortification you receive a NotImplemented exeption... Is there another means of distorting an image beyond skewing?
-
A code example : [Code] Dim MyWindow as TheFormIMade Sub AddOrFocusWindow If MyWindow Is Nothing MyWindow = New TheFormIMade Else MyWindow.Focus End If End Sub [/Code]
-
I'm just throwing an idea out there... You can retrieve and set the raw rich text from a rich text box. You could construct your own raw rich text if you learn a little about rtf format and assign it to the RichTextBox's Rtf property. For example, to insert your name into the RichTextBox you could maintain a raw rtf string that includes "{\colortbl ;\red0\green0\blue255;}" somewhere in the rtf (not sure exactly where, but this adds blue to the color table), and then insert this: "\cf1\b" & Name & ": \cf0\b0" & Message into the rtf in order to insert the message with the name in blue bold and message in black regular. Assign this to the richtextbox's Rtf property and... voila! Formatted rich text. Just insert your new messages in the rtf string like this, and assigning it to the richtextbox's rtf property.
-
I have never found myself porting more than a few lines of .Net code to VB6 code. But consider the rare but possible circumstances of two companies (or even two amateur programmers) who already have two different versions of Visual Basic and do not plan on swiching versions but would like to share code. Or, what if you begin writing a program in VB.Net and decide to switch to VB6 because it consumes less memory, or if you have a large base of preexisting VB6 code and a small amount of .Net code you want to use in a project you are creating, in which case it would be easier to port the .Net code. Like I said... I try to stay away from the VisualBasic namespace. But there may be reasons to stick to the Visual Basic runtime libraries in some cases. I wouldn't want to put myself into a situation where I had to port a large amount of file parsing code that uses the StreamReader class... or a configuration management class that uses the RegistryKey classes. Edit: ...or what if you wanted to turn .Net UserControls into ActiveX controls...
-
Woah!!! Hold on... while it is true that any functionality found in the Microsoft.VisualBasic namespace can almost always be reproduced by classes in other namespaces and I personally recommend using non-Visual Basic methods for portability and readability (for those who use c# or any other .net languages), I am under the impression that the VisualBasic namespace is still considered part of the Visual Basic language, not just for backwards compatability. The VisualBasic namespace is certainly never going to be obsoleted or depreciated as a whole as long as Visual Basic is around! While there are reasons why one might want to avoid the VisualBasic namespace there are also reasons why one might prefer the VisualBasic namespace... for instance if you want your code to be more portable between VB6 and VB.Net. It is a matter of circumstance and preference.
-
Alright, thanks divil. I had noticed that some controls were missing properties found in their base class and was confuddled when there was no appearent way to do it.
-
You want to add up the digits??? The problem appears to be that you are trying to parse a char. I believe you can only parse a string. What you might want to do (if you are trying to do what i think you are) is take the unicode values... subtract 48 (this is the unicode for 0; it will yeild 0 for '0' and 1 for '1' and 2 for '2,' etc...) and add those up. You can also convert each char to a string and parse those. I don't really know c#, but i know c++ and i know vb so lets see what happens... int addsomedigits(void) { string str=Console.ReadLine(); int len = str.Length; int total = 0; for (int i = 0; i < len; i++) total += System.Int32.Parse(str[i].ToString); } [/Code] My casing is probably not 100% correct... I usually program in VB. But the main idea is to create a "total" variable to store a running total and use a for loop to loop through the chars, convert them to strings, parse them as int32s, and add them to total. I don't have C# so I can't test this... but i tried.
-
I have a gig of ram. It seems to me that when i reduced my pagefile to a much smaller amount... 350 megs... my computer got faster. Until i began writing programs and i had 12 IE windows open and studio and photoshop and 3 instances of paint and 2 explorer windows... and ran out of pagefile space. But windows is recommending me 766 megs. thats closer to two thirds than it is to three halves (150%). Not sure what my point is.
-
I am creating a UserControl (which, of course, inherits the UserControl class). My class has three properties (of type Image). These images are set to the UserControl's BackgroundImage property to create a visual effect for normal, hover, and pressed states. The problem occurs when my control is instantiated on a form at design time. The problem is that along with my three image properties the public property BackgroundImage (from the base class UserControl) appears in the properties pane. It shows the image that is currently displayed on my control. It can also be manually set to a different image (that is, one that is not my normal, hover, or pressed image) altogether. While this behavior is certainly not the end of the world, it is also certainly undesirable. So, finally, what I would like to know is if it is possible to HIDE this member from other accessing classes (NOT shadow it) so that it dissapears completely from my derived class's interface. And (of course) if it is possible, how do I accomplish it?
-
And just incase anyone wants the code... Dim WithEvents Palette As New Palette Dim PaletteWasVisible As Boolean Dim AppLostFocus As Boolean Private Sub frmMain_Deactivate(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Deactivate, Palette.Deactivate Application.DoEvents() If ActiveForm Is Nothing Then PaletteWasVisible = Palette.Visible Palette.Visible = False AppLostFocus = True End If End Sub Private Sub frmMain_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated, Palette.Activated If AppLostFocus Then Palette.Visible = PaletteWasVisible AppLostFocus = False End If End Sub For photoshop style tool windows: Dim WithEvents Palette As New Palette Dim AppLostFocus As Boolean Private Sub frmMain_Deactivate(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Deactivate, Palette.Deactivate Application.DoEvents() If ActiveForm Is Nothing Then Palette.TopMost = False AppLostFocus = True End If End Sub Private Sub frmMain_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated, Palette.Activated If AppLostFocus Then Palette.TopMost = True AppLostFocus = False Me.Focus() End If End Sub