Jump to content
Xtreme .Net Talk

John_0025

Avatar/Signature
  • Posts

    38
  • Joined

  • Last visited

Everything posted by John_0025

  1. You can use the new keyword to do it. public class Class1 { public static int MaxWheels { get {return 1;} } } public class Class2 : Class1 { public static new int MaxWheels { get { return 4; } } } I'm not sure why you would want to do this. vechicleBase.MinimumWheels is meaningless without knowing what type of vechicle it is. I would just have a static field in the derived classes. public class baseVechicle { public virtual int MinimumWheels { get { return 0; } } } public class Car: baseVechicle { public static int minWheels = 4; public Car (int wheels) { if(wheels < minWheels) { //do error stuff } } public override int MinimumWheels { get { return minWheels; } } } public class UserClass { public void main() { baseVechicle myVechicle; int test = Car.minWheels; myVechicle = new Car(5); int anotherTest = myVechicle.MinimumWheels; } }
  2. Joe Mamma is correct. However I don't think the class factory should be in the baseclass. It doesn't make sense for a base class to contain information about classes that are derived from it. public interface iBaseClass{} public class Class1: iBaseClass{} public class Class2: iBaseClass{} public class Class3: iBaseClass{} public class ClassUser { public enum ClassType { class1, class2, class3 } public void Test() { iBaseClass bc1 = Create(ClassType.class1); iBaseClass bc2 = Create(ClassType.class2); iBaseClass bc3 = Create(ClassType.class3); } public iBaseClass Create(ClassType aClass) { switch (aClass) { case ClassType.class1: return new Class1(); case ClassType.class2: return new Class2(); case ClassType.class3: return new Class3(); default: return null; } } } p.s. This looks like a project where using an interface instead of a base class might be better.
  3. The 'using' statement is pretty neat. However it has a completely different use to the 'with' statement in VB. It is used for making sure that your objects is always terminated (couldn't think of a better word) even when there is an exception. The variable or object can only exist within the using statement.
  4. [0-9]{1,} will match the numbers in your string. The code below will return an array of all the numbers in your string. i.e. "Session73Number" will return "73" "Session73Number532" will return "73" and "532" Public Shared Function ReturnNumericValues(ByVal Text As String) As ArrayList Dim myRegExp As New System.Text.RegularExpressions.Regex("[0-9]{1,}", RegexOptions.IgnoreCase) Dim Matches As System.Text.RegularExpressions.MatchCollection Matches = myRegExp.Matches(Text) Dim myMatch As System.Text.RegularExpressions.Match Dim matchedValues As New ArrayList For Each myMatch In Matches matchedValues.Add(myMatch.Value) Next return matchedValues End Function
  5. This should work. "\+?[0-9]* \(?[0-9]*\)? [0-9]*" Some things that might help you. '\' - means ignore an special meaning the character may have to the regular Expression. i.e. '+' normally means to search for 1 or more occurrence of something. '[' and ']' - this looks for any single occurrence of the character with in the square brackets. In this case '0-9' '*' - looks for 0 or more occurrence of the proceeding character. so [0-9]* looks for 0 or more numbers. Note I find using '*' can be dangerous. '?' - means to look for 0 or 1 occurrence of the character before. You can also use {0,1}. The curley brackets mean you can specify a range of occurrences you are looking for or an exact number {2}. You may find this useful to specify exactly how many numbers you are expecting and replace the '*' above. To make the pattern a bit more reliable Hope this helps.
  6. This works a lot faster, but doesn't explain why the worksheet object was so slow. :confused: Public Sub New(ByVal oExcel As WorkBookSelection.ExcelWorkBook) Dim myWorksheet As Excel.Worksheet = oExcel.WorkSheets(oExcel.LookUpSheet) Dim IntRow As Integer Dim IntColumn As Integer Dim oFirstCell As Excel.Range = myWorksheet.Range("A2") Dim oLastCell As Excel.Range = myWorksheet.Range("A1").End(Excel.XlDirection.xlDown) oLastCell = myWorksheet.Cells(oLastCell.Row, LookUpColumn.MaxColumn) Dim myRange As Excel.Range = myWorksheet.Range(oFirstCell, oLastCell) Dim Values As System.Array = myRange.FormulaR1C1 Dim DataProperties(LookUpColumn.MaxColumn) As String For IntRow = 1 To Values.GetUpperBound(0) For IntColumn = 1 To Values.GetUpperBound(1) DataProperties(IntColumn) = CType(Values.GetValue(IntRow, IntColumn), String) Next DataCollection.Add(key:=AttributeProperties(LookUpColumn.DataName), item:=AttributeProperties) Next End Sub
  7. I'm trying to open an Excel workbook and read in the data. It works but it is really slow. This line is taking all the time myRange = myWorksheet.Cells(IntRow, IntColumn) [/Code] This is the full code [Code] Public Sub New(ByVal oExcel As WorkBookSelection.ExcelWorkBook) Dim myWorksheet As Excel.Worksheet = oExcel.WorkSheets(oExcel.LookUpSheet) Dim IntRow As Integer = 2 Dim myRange As Excel.Range Dim IntColumn As Integer Do Until myWorksheet.Cells(IntRow, 1).Value = "" For IntColumn = 1 To LookUpColumn.MaxColumn myRange = myWorksheet.Cells(IntRow, IntColumn) Next IntRow = IntRow + 1 Loop End Sub [/Code] oExcel is defined as [code] oExcel = GetObject(, "Excel.Application") My guess is that it is to do with late binding. Has anyone had this problem Thanks for any help.
×
×
  • Create New...