|
dear all
i would like to calculate the ATAN(), but how to add math library or component to project? thanks a lot.
|
|
|
|
|
You should be able to refer to the static Math class, like this
Math.Atan() The Math class is part of the System namespace and should already be available in your project without needing to add additional references.
Scott Dorman Microsoft® MVP - Visual C# | MCPD
President - Tampa Bay IASA
[ Blog][ Articles][ Forum Guidelines] Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
|
|
|
|
|
|
Well for 1, if all these classes are in the same namespace you wont be able to compile.
You can't have multiple classes with the same name in any namespace (except with partial classes ... but those are really only one class spread over multiple files).
You have declared the Hello class 3 times, that is not even close to valid.
2nd;
in all your classes you override your function 'hi' with a different signature than the one defined in Hello. A signature is a combination of the name of the function and the parameters it expects. For your 'hi' function in [Hello] you declared it as not expecting any parameters, the in your inherited classes you are trying to override it with a function that expects a string as a parameter.
You should really read this article[^] to help you understand inheritance because it seems like your not totally understanding it.
so your code should look something like this; (Probably wont compile because my VB is very rusty)
public mustinherit class Hello
'What you had
public MustOverride Function hi() as string
'What i added because you were trying to override this without having it
public MustOverride Function hi(byVal name as String) as string
end class
public class NorthEasterner
inherits Hello
'this HAS to be overriden because its declared as 'MustInherit'
public Overrides Function hi() as String
'No name was passed in so just welcome the stranger
return "Hello Stranger"
end function
'this HAS to be overriden because its declared as 'MustInherit'
public Overrides Function hi(ByVal name as String) as String
return "How ya doin," & name
end function
end class
public Class DragRacer
Inherits Hello
'this HAS to be overriden because its declared as 'MustInherit'
Overrides Function Hi() As String
Return "Start your engines!"
End Function
'this HAS to be overriden because its declared as 'MustInherit'
public Overrides Function hi(ByVal name as String) as String
return "Start your engines " & name & "!"
end function
End Class
public Class Euro
Inherits Hello
'this HAS to be overriden because its declared as 'MustInherit'
Overrides Function Hi() As String
Return "Caio"
End Function
'this HAS to be overriden because its declared as 'MustInherit'
public Overrides Function hi(ByVal name as String) as String
return "Caio " & name
end function
End Class
You could put all of these classes in separate code files, just make sure they are all in the same namespace and your golden. By default all of the code files you add should share the 'Default Namespace' defined in the project properties dialog.
If at first you don't succeed ... post it on The Code Project and Pray.
|
|
|
|
|
|
Celina69 wrote: I have an assignment
so it is YOUR assignment. we don't do homework here, and your prof probably reads this site too.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Great ...
You NEED to read up on inheritance, especially if this is a project for school.
Inheritance is a very important aspect of the .NET framework ( or any OO language for that matter) and not understanding it will do nothing but cause headaches in the future.
I'm sure you were assigned a book to read that covers this in painful detail.
I AM NOT GOING TO COMPLETE YOUR PROJECT FOR YOU, although I can't blame you for trying.
Not to mention I'm positive your teacher is familiar with CP, and I'm also pretty sure getting code of the net for your project is a big no no.
If at first you don't succeed ... post it on The Code Project and Pray.
|
|
|
|
|
The obvious thing to do is to create a new project (probably a Console app) and paste the code snippets into it (one at a time).
The compiler will tell you if there any syntax errors.
You can fix those and then try running the code to see if there are any run-time errors (step through it with the debugger).
That way you will learn something.
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
|
|
|
|
|
|
Do not repost. It is considered rude here.
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
|
Sometimes silence can be deafening...
My advice is free, and you may get what you paid for.
|
|
|
|
|
I really cannot help you with your problem.
------------------------------------
"When Belly Full, Chin Hit Chest"
Confucius 502BC
|
|
|
|
|
employee information is privileged indeed.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
As there is no information do we assume you are not employed?
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
It has to be a candidate for best post ever !!!!
Steve Jowett
-------------------------
Real programmers don't comment their code. If it was hard to write, it should be hard to read.
|
|
|
|
|
I guess that you must be posting from The Empty Quarter[^]
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
in vb.net how i get the start and stop time in timer control... that mean if i having two textbox. if named as start and stop. in that i need to click mean the timer to start and click stop maen the timer will stop autimatically... i need a vb.net code for this concept..
|
|
|
|
|
What have you got so far?
My advice is free, and you may get what you paid for.
|
|
|
|
|
Very good!
Make the bugger work, I bet it is a homework problem for college.
------------------------------------
"When Belly Full, Chin Hit Chest"
Confucius 502BC
|
|
|
|
|
it is a trick question, you can't calculate time. Not even in VB. Tempus fugit.[^]
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Hello everybody,
within an otherwise more simple project I have to deal with something that goes far beyond my knowledge so far. Probably someone of you can help with hints or a snippet?
The goal is to display a picture format which isn't supported from gdi+ on a form. So I already had to go through a lot of advanced stuff with GCHandle etc., but meanwhile I'm far enough that something (coming from the picture file at least) shows on the screen... unfortunately it's only a mixture of colored pixels . Considering the picture specification (if you're interested you find it here[^]) each pixel is represented by a 32-bit word, that is (in my particular case) divided into three 10-bit-integers (RGB) and two padding bits (zero).
With the code below I create an array of 32-bit-integers from the image information in the file, which are supposed to represent the pixels. But how can I access the RGB information? I.e., how would I be able to derive 10-bit-integers from a 32-bit word? Or am I running into a dead-end with the whole concept?
Thanks for any help and advice! Please keep it a bit simple, since for me there seem to be several completely new issues hidden...
Michael
The main code I use is:
Public Sub DisplayImage(ByVal PicFile As FileInfo)
Dim W As UInteger = 200
Dim H As UInteger = 154
Dim stride As UInteger = 4 * W
Dim arrayImage() As UInt32 = MakePixelArray(PicFile)
Dim gch As GCHandle = GCHandle.Alloc(arrayImage, GCHandleType.Pinned)
Dim pBuf As IntPtr = gch.AddrOfPinnedObject
PictureBox1.Width = W
PictureBox1.Height = H
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
PictureBox1.Image = New Bitmap(W, H, stride, Imaging.PixelFormat.Format32bppRgb, pBuf)
gch.Free()
End Sub
Despite my picture (and the resulting array - see next snippet) is 2048 wide and 1536 high, I still have to set W and H to lower values in order to avoid an AccessViolationExcepiton. But that's another issue...
My actual problem seems to be in the 'MakePixelArray' function, because I can't retrieve the 10-bit-Integers needed for RGB from the DWORD. Here's what I have:
Private Function MakePixelArray(ByVal PicFile As FileInfo) As Array
Dim ft As FileStream = New FileStream(PicFile.FullName, FileMode.Open)
Dim brh As BinaryReader = New BinaryReader(ft)
ft.Position = 8192
Dim PixelArray(CInt(PicFile.Length - ft.Position) / 4 - 1) As UInteger
For i = 0 To (PixelArray.Length - 1)
Dim buff As UInteger = SwapDWORD(brh.ReadUInt32)
PixelArray(i) = buff
Next i
ft.Close()
brh = Nothing
ft = Nothing
Return PixelArray
End Function Just for completion here's the SwapDWORD function which is needed because the file is written in big endian:
Private Function SwapDWORD(ByVal i As UInt32) As UInt32
Return ((i And &HFF) << 24) + ((i And &HFF00) << 8) + ((i And &HFF0000) >> 8) _
+ ((i >> 24) And &HFF)
End Function
|
|
|
|
|
Something like:
Dim buff As UInteger
buff = &H33388911
Dim Red As UInt32 = (buff And &H3FF)
Dim Green As UInt32 = (buff And &HFFC00) >> 10
Dim Blue As UInt32 = (buff And &H3FF00000) >> 20
This example would give Red = &H111, Green = &H222, Blue = &H333.
2+2=5 for very large amounts of 2
(always loved that one hehe!)
|
|
|
|
|
Hi Moreno,
thank you for taking some time. Since I'm a bit clumsy with Hex-stuff I just went and tried your piece of code, replacing the 'buff' value with a UInt32 read from the file (and swapped).
The changed function now considers that the array only consists of 3 Elements (RGB) per pixel instead of 4 (bytes). It now reads like
Private Function MakeRGBArray(ByVal PicFile As FileInfo) As Array
Dim ft As FileStream = New FileStream(PicFile.FullName, FileMode.Open)
Dim brh As BinaryReader = New BinaryReader(ft)
ft.Position = 8192 ' start with first pixel after the header
' change array dimensions from 4 bytes per pixel to 3 (RGB)
Dim RGBArray(CInt(PicFile.Length - ft.Position) / 4 * 3 - 1) As UInt32
For i = 0 To (RGBArray.Length - 1) Step 3
Dim buff As UInt32 = SwapDWORD(brh.ReadUInt32)
RGBArray(i) = (buff And &H3FF)
RGBArray(i + 1) = (buff And &HFFC00) >> 10
RGBArray(i + 2) = (buff And &H3FF00000) >> 20
Next i
ft.Close()
brh = Nothing
ft = Nothing
Return RGBArray
End Function
To make it short: I can't tell if your idea works, since there's no reasonable result - just a different very bluish pattern. And to be honest: I'm also afraid there's something else wrong with my code, too? As you see in the main function, I also have to use the 'Imaging.PixelFormat.Format32bppRgb' parameter when creating the new bitmap. Changing it results in an ArgumentException
BTW: With your code added, the first pixel returns buff=562758160 (&H218B0210) exactly in the order like it's written in the file (==> Red=528, Green=704, Blue=536)
Do you probably have another hint where I'm trapped in my code salad?
Thank you again,
Michael
|
|
|
|
|
Hi Michael,
Please note that mine was just an example: you should check which is the specific data format in your file: in my example, I gave it for granted that the 1st 10 bit would hold red, then 10 bits for green and finally 10 bits for blue. And no alpha. This might be different from the actual file format you're using.
If you want to share your file and the format, I might be able to help you more.
EDIT: share your code for drawing the picture, if you want - the problem may be there (since you say red, green and blue components seem to be read correctly from the data file).
2+2=5 for very large amounts of 2
(always loved that one hehe!)
modified on Thursday, August 6, 2009 1:53 PM
|
|
|
|