snarfblam
Leaders-
Posts
2156 -
Joined
-
Last visited
-
Days Won
2
Content Type
Profiles
Forums
Blogs
Events
Articles
Resources
Downloads
Gallery
Everything posted by snarfblam
-
Nooooo! Nooooo! I use VB, and I hate and do not use ReDim. There is a better way! You do it just like c#. private arrGrid(,) as GridSquare Sub New() ' TotalSqrt is the SquareRoot of the number of squares in total needed ' in the GameBoard. ' ie 16 squares would have a TotalSqrt = 4. arrGrid = new GridSquare(TotalSqrt - 1, TotalSqrt - 1) {} '<--Note the curly braces 'ALSO NOTE that a new array(4, 4) will yeild an array with 25 elements 'The bounds will be (0-4, 0-4) instead of (0-3, 0-3) End Sub The difference is that in vb, since arrays use parentheses () instead of square brackets [] for the array indecies, you just need to throw on some empty curly braces {} to tell vb that you are creating an array and not calling a constructor. Well... you also specify the upper bound instead of the amount of elements in VB, as I noted in the comments in the code above. X = New GridSquare([i]parameters[/i]) 'Object creation syntax, calls constructor Y = New GridSquare([i]bounds[/i]) {} 'Array creation syntax, requires empty initializer to disambiguate
-
Not at all familiar with sockets. Played around with winsock a bit in vb6, but never quite figured it out. And you can add handlers any time you want for any controls and any handlers you want, which is useful for, say, dynamically adding controls to your form and being able to handle their events. Look up the details on the AddHandler statement if you want to learn more.
-
You could make a generic click event handler function and dynamically add the handlers. Here, reusable code: 'This is our event handler Private Sub Generic_Click(ByVal sender As Object, ByVal e As EventArgs) MessageBox.Show("I been clicked") End Sub 'This function will add the specified handler to a control and any controls it contains Private Sub AddGenericClickHandler(ByVal Parent As Control, ByVal Handler As EventHandler) For Each thing As Control In Parent.Controls AddHandler thing.Click, Handler Next AddHandler Parent.Click, Handler End Sub Just put this line in your Sub New() or constructor: AddGenericHandler(Panel1, AddressOf Generic_Click)
-
newbie Q: creating a global variable array of strings?
snarfblam replied to ThienZ's topic in Visual C# .NET
I just tried that in #develop, and it came up as a build error telling me that the brackets need to come before the identifier (i.e. on the type specifier, "strings", i assume) -
The "classic windows" interface is considered by many to be the ugliest operating system around. Thats why windows xp introduced us to visual styles, and thats why so many applications, including some of Microsofts own programs (think Media Player, messenger) are skinned. Besides that, a skin can give a program distiction and set it apart from other programs, and in some cases can improve or modify functionality. Are these good enough reasons? Granted some skins just make an app more confusing or cluttered looking, but skins are fine when used appropriately. If you are making a simple or small program, there isn't much need to toss a skin on there. When used with descretion and implemented well, however, a skin can be a good thing.
-
i know im overreacting but... Oh, gee, thanks for dumbing it down for a moron like me. I just noticed that more than once you have given a reply in regex that is not necessarily self explanatory to those who did not write it and especially those not particularly familiar with regex, like me. I know what \w is, thanks. I know what * is. I know what + is. I know what [aeiou] does. I can put the pieces together too and disect them as well, but it is not necessarily clear to everyone, especially the layman, what a pattern as a whole might return for matches. A one line explaination of what you are posting is too much to ask for? I personally prefer to explain all of my code that somebody might not find self explainatory, just so more people can benefit from my answer, and I certainly do not do so in a condescending or insulting manner. Please, play nice with those like me who are not gurus like you. I'm here to learn and try to help, not to have people complain at me cause they have to dumb down their "self explanatory" regex pattern. I am new to regex, and do not have a comprehensive understanding of it. Sorry. But, after all, that's why I'm here.
-
If it is worth the one second wait and the $189 to you, go for it. It looks like its easy to use in your application. Personally, I don't pay for anything. If I can't get something for free or make it myself, I just forget about it. But that's probably not always the best policy. I personally also can't stand waiting for a program's window to open after I click the Icon. The faster, the better. But thats just me.
-
Hey, uh, HJB417, an explaination is always nice... [^\s]+[aeiou]+[^\s]+ I'm not very good with regular expressions, and I'm not sure what that is. Non-whitespace char(s), followed by vowel(s), followed by non-whitespace char(s)? Am I correct...? If so, what is it supposed to find? If you are looking to find all the words, wouldn't this work? \s\S+\s Non whitespace surrounded by whitespace?
-
What is wrong with white? It is consitant with the OS. Anyways, I don't know how to change the color of the date time picker. The BackColor property doesn't work. If you are only using it to pick the date and you are skinnig or just making an app w. your own color scheme, w/e, a solution that I found to this problem is to make a label or your own control that has the appearence you want, and when the user clicks it, show a previously hidden MonthCalendar control with your preferred colors. This has many drawbacks, however. The user can not edit the date in the collapsed view (unless you program this functionality), and the popup month selector must be contained within the bounds of the control.
-
(Thats exactly what my second example does)
-
Recover text between " in a file with C#
snarfblam replied to theflamme's topic in Regular Expressions
Okay... I'm not particularly familiar with either c# or regular expressions, so don't yell at me if it doesn't run right, but I whipped out my #develop, my Microsoft Visual Basic .NET, and made this and after a couple minutes of adding forgotten semi-colons and brackets and fixing my casing, I came up with this. void example() { string filetext = "\"string1\",\"string2\",\"string3\",\"string4\""; MatchCollection Matches = Regex.Matches(filetext, "\"([^\"]*)\",?", RegexOptions.IgnoreCase); string[] x = new string[Matches.Count]; for (int i = 0; i < Matches.Count; i++) { x[i] = Matches[i].Groups[1].ToString(); } //x[] now equals an array of the matches without the quotes } Don't know why that came out double spaced... -
newbie Q: creating a global variable array of strings?
snarfblam replied to ThienZ's topic in Visual C# .NET
Sorry, I'm not 100% familiar with c#. I'm trying to help, so no one get mad if I'm wrong aboot anything. Since String[] is a class (System.Array), I don't think that const is what you are looking for. With a class, if you don't want it to be modified, I think you would want to use readonly, which specifies that a variable can be modified only by initializers and the constuctor. The elements will still be modifiable, however, just not the reference to the array. In the second example I believe that you need to instantiate a new array before you initialize it. Here: public class myClass1 { private readonly string [] alphabeths = {"a", "b", "c"}; } public class myClass2 { private string [] alphabeths; public void myClass() { alphabeths = new string[] {"a", "b", "c"}; //'This could have also been readonly } } Also, depending on your needs (specifically on whether you are dealing with single charatcer strings), a char array might work. Try this: public class myClass2 { private char [] alphabeths; //'I believe that readonly would work here too public void myClass() { alphabeths = "abcdefghijklmnopqrstuvwxyz".ToCharArray; } } -
In all honesty, I don't really know much of anything about regular expressions, except what I learned while looking for this answer. My guess is that you should do a case-insensitive replace, where matches are effectively replaced with the pattern they matched. I don't think this is exactly what you want, but it is a start. The secret would be RegexOptions.IgnoreCase. 'Import the RegularExpressions namespace Result = Regex.Replace("I want me to be capitalized", "\bMe\b", " Me ", RegexOptions.IgnoreCase) ' Result = "I want Me to be capitalized" Also, I found this in the help (ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/cpref/html/frlrfSystemTextRegularExpressionsRegexClassReplaceTopic.htm). I think it would probably suit your needs better than any code I wrote for regular expressions. Imports System.Text.RegularExpressions Class RegExSample Shared Function CapText(m As Match) As String ' Get the matched string. Dim x As String = m.ToString() ' If the first char is lower case... If Char.IsLower(x.Chars(0)) Then ' Capitalize it. Return Char.ToUpper(x.Chars(0)) + x.Substring(1, x.Length - 1) End If Return x End Function Public Shared Sub Main() Dim text As String = "four score and seven years ago" System.Console.WriteLine("text=[" + text + "]") Dim result As String = Regex.Replace(text, "\w+", _ AddressOf RegExSample.CapText) System.Console.WriteLine("result=[" + result + "]") End Sub End Class
-
Well, I'll be damned. You lose the nifty xp style blue borders, but it works.
-
You want to... remove the titlebar? and keep the rest of the blue borders? If I am right, then Why? And regardless of why, you will need to draw it yourself, and either set it as a bitmap to the background property, or draw it yourself with GDI+ in the paint event.
-
Its amazing how often this question is asked. I personally preferred instantiating my forms before using them even in vb6.
-
If you want to be consistent with the OS, use xp styles. If you are going for a complete skin, like media player, then by all means use custom controls.
-
Sub Download() Sorry, I should have googled first. Using what I found on the net, I wrote this function in about ten minutes... Public Shared Sub Download(ByVal URL As String, ByVal FileName As String) Dim Request As HttpWebRequest = CType(HttpWebRequest.Create(URL), HttpWebRequest) Dim Response As HttpWebResponse = CType(Request.GetResponse(), HttpWebResponse) Dim WebStream As Stream = Response.GetResponseStream() Dim InputBuffer() As Byte = New Byte(CInt(Response.ContentLength) - 1) {} WebStream.Read(InputBuffer, 0, InputBuffer.Length) Dim FileStream As New FileStream(FileName, FileMode.OpenOrCreate, FileAccess.Write) FileStream.Write(InputBuffer, 0, InputBuffer.Length) WebStream.Close() FileStream.Close() End Sub
-
Is there any quick and easy way to download or create a stream for a text file on the internet?
-
Okay, there is a lot of misinformation about the .EnableVisualStyles method here. First of all, no, Windows does not offer Xp styles on Windows 2000, even if you call EnableVisualStyles. Windows only offers Xp styles in Xp. Like DiverDan said, you need to use custom controls, or something other than OS or .NET rendered controls (maybe you can just make owner drawn buttons....). If the user is using Windows Xp (regardless of which OS you are developing in), EnableVisualStyles will work JUST FINE. You just need to know when and how to use it. NOT after InitializeComponents. NOT in the Form.Load event handler. It must be called before ANY controls are created, preferably in Sub Main. Add this into your main form's code: Public Shared Sub Main Application.EnableVisualStyles() 'Xp styles, LIKE MAGIC! Application.DoEvents() 'EnableVisualStyles bugs gone, LIKE MAGIC! Application.Run (New FrmMain) '<--Replace FrmMain with the name of your main form class End Sub If you already have a public sub main just insert the first two lines from the sub main shown above into your sub main. I have never had any problems with EnableVisualStyles. Maybe if you are subclassing the windows controls or directly handling the windows messages it could change some behavior that could cause you problems. Most likely not though. Give it a whirl. If exceptions start getting thrown it is easy enough to fix, just remove the five lines of code, no worries. Keep in mind that you won't see any difference since you are using Windows 2000. Any of your users running Windows Xp will see the difference. As far as Icons go, I draw my own ARGB icons in photoshop and save them with a plugin called IconFactory (IconFactory is not free). [Edit]A manifest would certainly also work, but it requires that the additional .Manifest file be present in the folder that the exe is in. The "Visual Studio .NET 2003 Combined Collection" help files include a good example.[/Edit]
-
You can not change the array size. In VB6 (i don't know if it is available in .NET) there was redim and redim preserve which resized the arrays, but these actually created new arrays and if you used preserve it just copied the contents. In .NET if you want arrays that are variable in size, you have two options i can think of. You can use the System.Collections.ArrayList class, or when you want to resize an array, create a new one like this: Dim X(8) As String 'RESIZE X = New String (10) {} 'RESIZE AND PRESERVE Dim NewX as New String(10) {} Array.Copy(X, NewX, Math.Min(X.Length, NewX.Length)) X = NewX
-
How do I create an array from the selected items in a ListBox?
snarfblam replied to PaulieORF's topic in Windows Forms
I would think that in most cases, you could use the .SelectedItems collection in place of an array. If you need the items in the form of an array, however, here: 'Try using a more specific type, such as String if the listbox contains strings Dim X As Object() 'Declare Variable X = New Object(ListBox1.SelectedItems.Count - 1) {} 'Create properly sized array ListBox1.SelectedItems.CopyTo(X, 0) 'Copy selected items to the array -
If you are not the author of this class, then there is no way to see if the value has been set because a short can never be null. Alternatively (assuming that you are the author of this class), although I would not personally recommend this, you could declare both the property and the underlying variable it is stored in as type object which would be null until set to a short, but this can cause issues with types and introduce bugs. Best to go with the method recommended by IngisKahn.
-
Form.ModifierKeys What you need is the Shared property System.Windows.Forms.Form.ModifierKeys... If Not CBool(Form.ModifierKeys And Keys.Control) Then 'Perform validation or whatever here End If Use this property whenever you need to know if the user is holding shift, alt, or control. The example above would work if the user was holding shift and/or alt in addition to control. If you want it to work for only control, replace the "And" with an "=".
-
According to the code provided, you are assigning an object to a variable of type 1-dimensional array of objects. If you have option strict on, this will trigger a compiler error. If option strict is off, it should throw an invalid cast exception. My best guess is that you have option strict off and in addition to the invalid cast, you have an error that causes a null reference exception to be thrown in the constructor of your class. If you want more help, as plausibly damp said, you need to post more code (and maybe show us what line or function is causing the exception).