|
I completely boogered my project. I have to rewrite everything and test what you got there. I think I need to go one step further with what you gave me there though. It looks like that just gives me the paths to the directories that contain a file called settings.txt, which is great thats the first step.
Here's a layout of sorts to illustrate what I want to accomplish.
There are 3 folders with the settings file.
D:\Temp\Folder1\Settings.txt
D:\Temp\Folder2\Settings.txt
D:\Temp\Folder3\Settings.txt
in the text file, I have settings that look like this
[Name]
name=
and the ini code I have up there grabs the verbage in that section. So let's say the names are like this:
Folder1 - name=John
Folder2 - name=Sam
Folder3 - name=Zach
I want the comboBox to have a list like this:
John
Sam
Zach
I hope that helps understand my goal. Thank you for your reply! I am working on rebuilding my project right now.
|
|
|
|
|
Goaty65109 wrote: that just gives me the paths to the directories that contain a file called settings.txt
Not quite - if you add a button to your form and run that code in the button click, you will find it prints the full path to all the files called "Settings.txt". So all you have to do is feed the string into your IniFile constructor and access the file:
IniFile ini = new IniFile(file); You can then add each setting value to your ComboBox Items collection. You don't want to set the Text property each time, because that will only show the last value you set into it - it is just a string property after all!
If you get an email telling you that you can catch Swine Flu from tinned pork then just delete it. It's Spam.
|
|
|
|
|
So let me make sure I understand this correctly, and please forgive me as I am completely novice and am running through as many training videos as I can all the while trying to dream big with my own personal projects.
After I generate that information, I just need to plug this into a button (or form_load as intended):
IniFile ini = new IniFile(file);
comboBox = ini.IniReadValue("Info", "Name");
and it will simply fill my combo box with my desired settings? I have a feeling I am wrong as this sounds too simple, or maybe I just hit the jackpot on my biggest hurdle. Thank you so much for working with me.
|
|
|
|
|
Not quite that simple - you need to use both bits of code, and you can't assign a string to a ComboBox variable!
Try something like this:
string[] SettingsFiles = Directory.GetFiles(@"D:\Temp\", "Settings.txt", SearchOption.AllDirectories);
comboBox.Items.Clear();
foreach (string file in SettingsFiles)
{
IniFile ini = new IniFile(file);
comboBox.Items.Add(ini.IniReadValue("Info", "Name"));
}
BTW: you probably don't need the "Ini" part on the method name "IniReadValue" - it is implied by the fact that it's an IniFile method.
If you get an email telling you that you can catch Swine Flu from tinned pork then just delete it. It's Spam.
|
|
|
|
|
You are absolutely amazing, thank you so much. I am still rebuilding, but I will get back with you with my results. Is there any way to give you props on this site? I would like to contribute to whatever the reputation tracker is. Thank you so much!
|
|
|
|
|
You're welcome!
You can vote on (almost) any message - in the forums there is a green up arrow beside the message that adds to the authors rep, and a red one which takes from it.
If you get an email telling you that you can catch Swine Flu from tinned pork then just delete it. It's Spam.
|
|
|
|
|
Question that came into my mind whilst I am close to being done rebuilding. Can I change the SearchOption.AllDirectories into something more specific? In case I copy and paste a directory to make a backup of the original settings? Like for instance, only look in folders that BEGIN with "BRD"? Thanks again.
SearchOption = "\\BRD*"); <--- just an example of what I mean
Edit: Ok it's all built. I am now running into an exception. Apparently, the name IniReadValue does not exist in the current context. But it exists in my ini class.
public string IniReadValue(string Section,string Key)
{
StringBuilder temp = new StringBuilder(255);
int i = GetPrivateProfileString(Section,Key,"",temp,255,this.path);
return temp.ToString();
}
|
|
|
|
|
No - the search only considers file names, it doesn't compare against the path. But it's pretty easy do check afterwards:
if (file.Contains(@"\BRD"))
{
...
}
Exception: (I suspect it's a compilation error?)
Show your code (cut'n' paste so you don't mistype - and try using the "code" widget above the text box to format your code - it makes it easier to read)
If you get an email telling you that you can catch Swine Flu from tinned pork then just delete it. It's Spam.
|
|
|
|
|
Here is my main form:
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using ReadWriteIni;
using Ini;
namespace ReadWriteIni
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
string[] settingsFiles = Directory.GetFiles(@"C:\\Users\\Name\\Desktop\\Projects\\test.Files\\Folders\\",
"Settings.txt", SearchOption.AllDirectories);
comboInst.Items.Clear();
foreach (string file in settingsFiles)
{
IniFile ini = new IniFile(file);
comboInst.Items.Add(Ini.IniReadValue("Info", "Name"));
}
}
}
}
And here is my Ini Class (Wish there was a spoiler tag to collapse this part...)
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
namespace Ini
{
public class IniFile
{
public string path;
[DllImport("kernel32")]
private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
public IniFile(string INIPath)
{
path = INIPath;
}
public void IniWriteValue(string Section, string Key, string Value)
{
WritePrivateProfileString(Section, Key, Value, this.path);
}
public string IniReadValue(string Section, string Key)
{
StringBuilder temp = new StringBuilder(255);
int i = GetPrivateProfileString(Section, Key, "", temp, 255, this.path);
return temp.ToString();
}
}
}
|
|
|
|
|
Remember that c# is case sensitive:
IniFile ini = new IniFile(file);
comboInst.Items.Add(Ini.IniReadValue("Info", "Name"));
------------------------------------^ Becomes:
IniFile ini = new IniFile(file);
comboInst.Items.Add(ini.IniReadValue("Info", "Name"));
------------------------------------^ You need to make the two names match!
If you get an email telling you that you can catch Swine Flu from tinned pork then just delete it. It's Spam.
|
|
|
|
|
Well I'll be damned. It works! Words cannot express my thanks. I can now move on with the fun, visual side of things and actually get this mess put together. You sir are fantastic. Bookmarked, as well as a couple of your Guides (I'll probably be seeing you again once I wish to make simple SELECT queries to SQL).
It's 6:15 here, been trying to tackle this since 9pm yesterday, you saved me so much time and I appreciate it. You have a good day man! and good night.
|
|
|
|
|
You're welcome!
If you get an email telling you that you can catch Swine Flu from tinned pork then just delete it. It's Spam.
|
|
|
|
|
We have a Winforms form containing a textbox. The idea is that as you enter a string of hex characters these are trapped and are used to change the background colour of the texbox dynamically. So, if you enter ff0000 that would change the background colour to red. The user keystrokes are intercepted with the KeyPress and KeyDown to filter specific characters such as not allowing G, Y that sort of thing. All of this works okay and the texbox's text changed event correctly changes the colour.
The text in the textbox is mostly visible. If I set the foreground colour of the text to black there's no problem if you set the background colour to red (ff0000), blue (ff) but when you set it to black (0) or just-a-bit-away-from-black (1) you obviously can't see the text. If I set the forecolour of the text to white you get the same problem at the other end of the colour "spectrum". I thought of using grey as that's sort of midway but if you set the background colour to (808080) or near to then, well, you can see the problem!
The idea I hit upon and which works relatively okay is to invert the bits of the RGB and set the foreground colour to that. So, depending on what's entered you might have a background colour of slightly-purpley-reddish-orangey-blue and the text might look like whitish-green-yellow-tinged-magenta-with-a-touch-of-russet-but-not-too-much.
It works upto a point if you don't mind your foreground colour looking like it's injected pure LSD but I'm wondering if there's a more optimal solution or suggestion you'd recommend? In other words, is there a good solution so that no matter what the background colour is set to, the foreground colour of the text within it can be displayed with a best fit contrast?
If there is one thing more dangerous than getting between a bear and her cubs it's getting between my wife and her chocolate.
|
|
|
|
|
I believe the answer lies in this[^] post.
/ravi
|
|
|
|
|
Ravi,
Thanks for the link. I tried it and it seems to do the job okay.
If there is one thing more dangerous than getting between a bear and her cubs it's getting between my wife and her chocolate.
|
|
|
|
|
Hello,
I have couple of question about if statement.
When I create password verifying program,
at least 8 characters long is
if (password.Length < 8)
valid = false;
like this, right?
Then, how can I make program that must contain at least one digit and one uppercase for the password.
Then, I tried to create
while (valid && i < 1)
{
if (!Char.IsLetter(custID[i]))
valid = false;
i++;
}
like this, but it's not working.
Please tell me.
|
|
|
|
|
|
You should be able to figure something out from the following
Password Strength Control
Regular expressions can help but they're not a silver bullet.
Q. Hey man! have you sorted out the finite soup machine?
A. Why yes, it's celery or tomato.
|
|
|
|
|
You need to read his earlier post. It's homework.
|
|
|
|
|
Ah, yes. missed that other post.
It's his own problem if he can't be bothered to *learn* and just copies stuff.
Q. Hey man! have you sorted out the finite soup machine?
A. Why yes, it's celery or tomato.
|
|
|
|
|
hi .
if(password.Length < 8) is extreme 7 character.
at least 8 character is this :
if(7<password.Length)
if(8<=password.Length)
but for second part of your question ... ! try to understand these codes and get some idea to mke your own .never copy and paste!(just a suggestion to improve your skills,ofcourse you are free to copy )
char[] Digits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
if (7 < password.Length)
foreach (char t in Digits)
if (password.Contains(t))
for (int h = 65; h < 90; h++)
if (password.Contains((char)h))
break;
modified 10-Mar-13 12:05pm.
|
|
|
|
|
In C# System.Char has a number of methods including isDigit()and isLetter()
|
|
|
|
|
yea , its more simple way . thanks for remind!
|
|
|
|
|
1. Sentence Capitalizer
Write a method that accepts a string object as an argument and returns a copy of the string with the first character of each sentence capitalized. For instance, if the argument id “hello, my name is Joe. what is your name?” the method should return the string “Hello. My name is Joe. What is your name?” Write a test program that will exercise this method (and display the result on the monitor.)
2. Password verifier
Imagine you are developing a software package that requires a user to enter his/her passwords. Your software requires that the user’s password meets the following criteria.
a. It should be at least 8 characters long
b. It should contain at least one uppercase and at least one lowercase letter
c. It should have at least one digit.
Write a method that verifies that a password meets the stated criteria. Write a test program to exercise these.
----------------------------------------------------
Hello,
I am asking you about creating C# program.
These two program to create are so complicated for me.
I was trying to figure them out for 2 weeks, but it's still not.
Teacher told me both program are used by "Regex" (Regular Expression) if possible.
Could you give me suggestion or a part of the program or how to do it?
Thank you.
|
|
|
|
|
Do your own homework.
Here's a tool that may help: RegexTester[^]
If you have trouble with what you come up with, we have a Regular Expressions forum
And I suspect that your teacher may be an idiot.
|
|
|
|