|
I have tried to figure something out that I want to write in code, but I couldn't find the solution. Until now. I found the following piece of code on the Internet today. Unfortunately, it is in the language of C (I think so), a language that I don't know anything about. So, I would be very grateful if anyone could translate it to Visual Basic code.
<br />
#include iostream.h<br />
<br />
int fak(int n);<br />
<br />
void main()<br />
{<br />
int x=5;<br />
<br />
cout<< x << "!=" << endl;<br />
cout<< fak(x) << endl;<br />
cout<< 5*4*3*2*1 << endl;<br />
}<br />
<br />
int fak(int n)<br />
{<br />
if (n<=0)<br />
return 1;<br />
<br />
else<br />
{<br />
int a = n*fak( n-1 );<br />
return (a);<br />
}<br />
}<br />
//OT
|
|
|
|
|
(Untested and VB.NET, so replace Integer with Long in VB6)
Function Factorial(ByVal n As Integer) As Integer
' AFAIK, you can actually do this as <= 1 instead
If n <= 0 then
return 1
else
return n * Factorial(n - 1)
end if
End Function
You might want to read up on recursive functions, as that is all this is.
--
Ian Darling
If I was any more loopy, I'd be infinite.
|
|
|
|
|
So there is a function to do n-factorial. I didn't know that. Well, I was hoping to find out how to write a for...while loop or something that does the same thing. I have spoken with my mathematics teacher and we are trying to find some algorithm to do n-factorial. I mean, a calculator doesn't know what, for example, "5!" is, does it? I tried to write a loop with "counter" that added "1" for every loop, and when "counter" had the same value as "n". It did not work, though.
But thanks for the help, anyway.
//OT
|
|
|
|
|
You can work out a factorial in a loop too (again VB.NET):
Dim total as Integer = 1 ' starting at 1 is important here
For i as Integer = 2 to 5 ' replace the 5 with a variable as necessary
total = total * i
Next i
--
Ian Darling
If I was any more loopy, I'd be infinite.
|
|
|
|
|
Thanks, but I have already worked it out. It was only one small adjustment I had to do in my code to make it worked.
I did it like this:
<br />
Dim x As Integer<br />
Dim y As Integer<br />
Dim counter As Integer<br />
Dim check As Boolean<br />
<br />
<br />
Private Sub Bttn_Fkltt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bttn_Fkltt.Click<br />
x = TxtBx_Fkltt.Text<br />
counter = 1<br />
check = False<br />
y = x * (x - 1)<br />
If x > 2 Then<br />
Do Until check = True<br />
counter = counter + 1<br />
y = y * (x - counter)<br />
If counter = x - 1 Then<br />
check = True<br />
Exit Do<br />
End If<br />
Loop<br />
Lbl_Fkltt.Text = y<br />
Else<br />
Lbl_Fkltt.Text = y<br />
End If<br />
End Sub<br />
Look at the code: If counter = x - 1 Then . Before, I had If counter = x Then , and with that code, y was multiplied with 0 in the end, resulting in y = 0.
//OT
|
|
|
|
|
I made some shaped forms... but I have never found
out How to create somthing like this shape, a recangle with rounded corners:
Look at the white area.. Click Here
any ideas?
I used this page
|
|
|
|
|
This code will generate a rectangle(200x200) with rounded corners...
Dim Path As New GraphicsPath
Path.AddArc(0, 0, 40, 40, 180, 90)
Path.AddArc(160, 0, 40, 40, -90, 90)
Path.AddArc(160, 160, 40, 40, 0, 90)
Path.AddArc(0, 160, 40, 40, 90, 90)
Me.Region = New Region(regionPath)
|
|
|
|
|
what's GraphicsPath? what's regionPath? ...
.. here we go again.
|
|
|
|
|
Thank you very much!!! No way I could find it by my self
|
|
|
|
|
Whoops regionPath is actually the variable Path of the type GraphicsPath... Sorry!
|
|
|
|
|
Hello,
I need to launch a simple text editot like WordPad. Does anyone have such a royalty-license free application? Or at least know where I can aquire one. I'm just getting into VB but I need this for a curent project asap.
I hope this is the proper forum for this question.
iaustin
Thank You
|
|
|
|
|
COuld try Textpad - excellent editor, and Shareware - will pop up with licence warnings every now and then, but otherwise exactly same as full version....
Just one question - why the FUNK do you want to use a text editor for VB????
Otherwise - if what you are asking is HOW to launch the editor, declare the ShellExecute function, and pass the filename in....(see MSDN or give me a shout if you want an example.
"Now I guess I'll sit back and watch people misinterpret what I just said......"
Christian Graus At The Soapbox
|
|
|
|
|
I have a datagrid on my form that is anchored to all sides but when I maximze the window only the datagrid anchors correctly but not the columns of data within it. Any idea where I am going wrong?
|
|
|
|
|
As far as I know there is no way to just set a property and anchor the columns to they resize auto like that.
Paul Watson wrote:
"At the end of the day it is what you produce that counts, not how many doctorates you have on the wall."
George Carlin wrote:
"Don't sweat the petty things, and don't pet the sweaty things."
Jörgen Sigvardsson wrote:
If the physicists find a universal theory describing the laws of universe, I'm sure the a**hole constant will be an integral part of that theory.
|
|
|
|
|
I need to set new color variable which contains
a specific color that I created...
I got its R/B/G values, How can I make a color variable called x that contain it...
and then If I have a button and I want 2 chnage its color I will use:
Button1.backcolor=x
Thank You Very much
|
|
|
|
|
ok , i didnt quite get what you write in the message.
to create a color from rgb:
Color c=Color.FromArgb(r,g,b);
to invert a color:
Color inv=Color.FromArgb(255-c.R,255-c.G,255-c.B);
(ps , that was c# code , but i just assumed your usinng vb.net?)
//Roger
|
|
|
|
|
|
Right, I have a set of Data Access Layer classes that represent their respective SQL Server tables.
I have a set of forms where I use the .DataBinding() for each control to bind to properties in my Data Access Layer classes.
This was all working great, until I moved the forms into an external .DLL. Now when I call the forms .Show() from the external .DLL I get the message:
"An unhandled exception of type 'System.OutOfMemoryException' occurred in system.windows.forms.dll" - Additional information: Error creating window handle.
I've traced through the code, and the externals forms will fire up perfectly fine into my apps MDI form, as long as no calls to the data binding take place.
Is there any reason why Data Binding won't work across .DLLs????
|
|
|
|
|
........and the solution is.....................pass your controls around by reference and not by value....ta da!!
|
|
|
|
|
I used
ie = CreateObject("InternetExplorer.Application")
ie.Navigate("test.html")
ie.ExecWB(SHDocVw.OLECMDID.OLECMDID_PRINT, SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER)
to print "text.html".
when the file has too many pages to print, it doesn't print all the pages..
suppose test.html has actual 20 pages to print but it only get 2 pages printed by using above code?
So I add
System.Thread.Sleep(5000) to give the time to printer to spool all and print all the pages..it helps.. but still only 5 pages printed and not all 20 pages..
how can i pause the program to wait printer to finish printing the document??
thanks
|
|
|
|
|
Well, basically I'm getting this error message when calling .Show() on a child form. Before anything is displayed, this exception is thrown.
Now it's in the slightly unusual situation, that the MDI window is in a VB.NET application, and all the child forms are supplied in a C# library. So I'm wondering if it's something to do with this??
Any suggestions, hints or tips?
|
|
|
|
|
Problem sorted - it was down to dumb user error
|
|
|
|
|
i have a access database(oledb not sql)
i have a datetimepicker and a datagrid in my form.
i would like know picking my data from my database with the datetimepicker.
when i choose 01/05/2003 from my datetimepicker, i would like only this data should be shown.
01/05/2003 James $5.000,15
01/05/2003 Mary $7.500,01
01/05/2003 Adam $25.99,45
Please Help,,,
sorry for my english,,,, türkish man in forum
Turan
|
|
|
|
|
Hi,
try reading this[^]Article
I wrote it as a reply to a similar Q.
|
|
|
|
|
Thanks for your answer...
I tryed this code;
komutum = "SELECT * FROM tblkomisyon WHERE Tarih =#" & DateTimePicker1 & "#"
but it gives this error
operator() '&' is not defined for types 'String' and 'Systems.Windows.Forms.DateTimePicker'
Any help please...
Turan
|
|
|
|