CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Oct 2009
    Posts
    10

    Is this possible?

    Hey, I am new to visual basic, and taking a class on it in school.

    Anyway, I was wondering if it was possible to have the user input data, and have the data SAVED to a file, so it could be resurrected later.

    Help is appreciated. BTW, I plan on staying on this forum for a while, and hopefully getting good.

  2. #2
    Join Date
    Apr 2008
    Posts
    725

    Re: Is this possible?

    /me looks at sign above door

    "Visual C++ Programming"

    yep, thought so.



    (yes it's possible)

  3. #3
    Join Date
    Oct 2009
    Posts
    10

    Re: Is this possible?

    Oh, and btw, if this is possible, could someone give me the coding for it? I am very new, and most likely would understand all of the terms within the code.

    BTW, a small prize may be awarded.

  4. #4
    Join Date
    Apr 2008
    Posts
    725

    Re: Is this possible?

    perhaps you misunderstand, this is a C++ forum, not a VB one.

  5. #5
    Join Date
    Oct 2009
    Posts
    10

    Re: Is this possible?

    OH yeah, very sorry. I meant Visual Studios! I always get those two mixed up.. =/

  6. #6
    Join Date
    Oct 2009
    Posts
    10

    Re: Is this possible?

    Nevermind, I figured it out, and it is fairly simple.

    My next challenge is this: I need to figure out a way to convert letters into asterisks when the user types in any type of character. Is this possible?

  7. #7
    Join Date
    Oct 2008
    Posts
    116

    Re: Is this possible?

    In C/C++ you can use cin, cout ( in iostream header) to have use input. And you can write your data to file by using ifstream or ofstream (in fstream header).

    Btw, you can read more in C/C++ books. Hope it help.
    My English is very bad. So tell me if Something I talked make u confuse.
    My Ebook Store: www.coding.vn/book.php

  8. #8
    Join Date
    Oct 2009
    Posts
    10

    Re: Is this possible?

    Thanks for your input Z, however I have already figured out how to do it. Although your way seems much more simple; are you sure it works? Anyhow, this is the code I came up with:
    Code:
    #include <iostream>
    using namespace std;
    int main()
    {
        char message[20];
    	FILE *test = fopen("test.txt", "w");
    	cout << "message: "; 
    	cin >> message;
    	fprintf(test, "&#37;s\n", message);
    }
    *I took the code from a much more complex program, and reduced the complexity significantly.*

    As well, my current issue is figuring out a way to convert characters into asterisks like a password field.

  9. #9
    Join Date
    Oct 2008
    Posts
    116

    Re: Is this possible?

    hi,
    Code:
    #include <iostream>
    using namespace std;
    int main()
    {
        char message[20];
    	FILE *test = fopen("test.txt", "w");
    	cout << "message: "; 
    	cin >> message;
    	fprintf(test, "%s\n", message);
    }
    It's ok.

    And "asterisks like a password field."

    I wonder whether you use console application or windows application.

    if you are in console application, maybe you can do it like that :

    Code:
    void input()
    {
      char c;
      char pass[100];
      int i = 0;
      printf("Your Pass: ");
      c = getchar();
      while(c != 13 && i <100) 
     {
        printf("*");
        pass[i++] = c;
    
      }
       
    }
    My English is very bad. So tell me if Something I talked make u confuse.
    My Ebook Store: www.coding.vn/book.php

  10. #10
    Join Date
    Oct 2009
    Posts
    10

    Re: Is this possible?

    Quote Originally Posted by zkidkid View Post
    And "asterisks like a password field."

    I wonder whether you use console application or windows application.

    if you are in console application, maybe you can do it like that :

    Code:
    void input()
    {
      char c;
      char pass[100];
      int i = 0;
      printf("Your Pass: ");
      c = getchar();
      while(c != 13 && i <100) 
     {
        printf("*");
        pass[i++] = c;
    
      }
       
    }
    Hmm, I tested it, but it does not work. It only prints 100 asterisks after you input the password.

    I was thinking about using a while statement..but I do not think it is possible.

    Thanks a bunch though for your contribution.

  11. #11
    Join Date
    Oct 2009
    Posts
    10

    Re: Is this possible?

    Well, I figured this one out on my own as well, if anyone wants to check it out, here it is:
    Code:
    #include <iostream>
    #include <string>
    #include <conio.h>
    using namespace std;
    void InputPassword(string &value);
    int main(void)
    {
        string pass;
        cout <<"Please enter your password: ";
    	InputPassword(pass);
        cout << endl << endl;
        cout << pass << endl << endl;
    }
    void InputPassword(string &value)
    {
    	char key;
    	do
    	{
    		key = getch();
    		value.push_back(key);
    		std::cout << "*";
    	}while(key != '\r'); //Quit if Enter is Pressed
    }
    Yep..the good 'ol do-while.
    Last edited by Coding_Bro; October 10th, 2009 at 03:57 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured