newbie question

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Jun 2005
Posts: 147
Reputation: ashneet is an unknown quantity at this point 
Solved Threads: 1
ashneet's Avatar
ashneet ashneet is offline Offline
Junior Poster

newbie question

 
0
  #1
Sep 9th, 2006
Well i need to make a program which would display a certain string in a triangle form in the middle of the console something like this:

  1.  
  2. t
  3. eee
  4. sssss
  5. ttttttt
it wont display right here but i think you get the point.

I am somewhat able to do that but i need to slow the display so that it looks like it is a triangle and want to be able to run it for as long as possible as this program is just for show...

  1. using System;
  2. class test {
  3. //Creating global variables
  4. protected static int orix;
  5. protected static int oriy;
  6.  
  7. //Function to print string in diffrent areas
  8. protected static void echo(string s, int x, int y) {
  9. try {
  10. Console.SetCursorPosition(orix+x, oriy+y);
  11. Console.Write(s);
  12. }
  13. catch(ArgumentOutOfRangeException error) {
  14. Console.Clear();
  15. Console.WriteLine(error.Message);
  16. }
  17. }
  18.  
  19. //MAIN PROGRAM
  20. static void Main()
  21. {
  22. string str = Console.ReadLine();
  23. int strlength = str.Length;//variable that keep string length
  24. int width = Console.WindowWidth, height = Console.WindowHeight;
  25.  
  26. //check to see if string is exist
  27. if(strlength != 0) {
  28. Console.Clear();
  29. orix = Console.CursorTop;
  30. oriy = Console.CursorLeft;
  31.  
  32. //check to see if the console width is 80 or set it
  33. if(width != 80) {
  34. Console.SetWindowSize(80, height);
  35. }
  36.  
  37.  
  38. int y = 0;
  39. while(true) {
  40. int hw = Console.WindowWidth/2;
  41. int halfway = hw;
  42. int ht = hw - strlength;
  43. int inc = 2;
  44. int incy = 0;
  45. int s = 1;
  46.  
  47.  
  48.  
  49. for(int i=0;i<strlength;i++) {
  50. if(i == strlength-1) {
  51. inc = -2;
  52. }
  53.  
  54. string stri = "";
  55. for(int n=0;n<s;n++) {
  56. stri += str[i];
  57. }
  58. s += inc;
  59.  
  60. echo(stri,halfway,y);
  61. y++;
  62. if(i == 0) {
  63. incy = -1;
  64. }
  65. if(halfway == ht) {
  66. incy = 1;
  67. }
  68. halfway = halfway+incy;
  69. }
  70. Console.WriteLine(strlength-1);
  71.  
  72. }
  73. }
  74. else {
  75. System.Console.WriteLine("A string needs to be entered for this program to work");
  76. System.Console.ReadKey();
  77. }
  78.  
  79. }
  80. }


it works for like a sec and there is text but it is so fast you cant read the text and then i get a error after that.

error:
The value must be greater than or equal to zero and less than the console's buffer size in that dimension.
Parameter name: top
Actual value was 3420.
Last edited by ashneet; Sep 9th, 2006 at 4:21 pm.
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 13
Reputation: virang_21 is an unknown quantity at this point 
Solved Threads: 0
virang_21 virang_21 is offline Offline
Newbie Poster

Re: newbie question

 
0
  #2
Jan 14th, 2009
Put
Console.ReadLine() when your app is exiting while loop. By that way you can keep your app running till user enter something.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: newbie question

 
0
  #3
Jan 15th, 2009
You're setting a cursor position beyond the bounds of your console window, it wont like that
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC