none
How can I retrieve a string array and byte array RRS feed

  • Question

  • Hello,

            I have a project i'm working on, I have everything working except the return of string array's

    and byte array's showing where I want them to show. I have them returning to a list box, but I want

    them to show in the text box where the ( string, expand string, DWord, QWord ) show. But I just

    can't figure that part out.

    Here is what I use in my project :

    // The code for the GetValue Method
    
    // =============== MainForm.cs =====================
    
    private string[] MS_Array = new string[] { };
    private byte[] B_Array = new byte[] { };
    
    private void BtnRefreshValueClick(object sender, EventArgs e)
    {
    	this.TxtValue.Text = this.SelectedProfile.GetValue(this.CboSection.Text, this.CboEntry.Text, "");
    }
    
    
    private void TxtValue_TextChanged(object sender, EventArgs e)
    {
    	this.UpdateComponents();
    	try
    	{
    		if (TxtValue.Text == "System.String[]")
    		{
    			listBox1.Items.Clear();
    			listBox1.Items.Add("This is the Multi-String value");
    			listBox1.Items.Add("");
    
    			string[] value = this.SelectedProfile.GetValue(this.CboSection.Text, this.CboEntry.Text, MS_Array);
    
    			for (int i = 0; i < value.Length; i++)
    			{
    				listBox1.Items.Add(string.Concat(value[i]));
    			}
    		}
    	}
    	catch { }
    	try
    	{
    		if (TxtValue.Text == "System.Byte[]")
    		{
    			listBox1.Items.Clear();
    			listBox1.Items.Add("This is the Binary value");
    			listBox1.Items.Add("");
    
    			byte[] value = this.SelectedProfile.GetValue(this.CboSection.Text, this.CboEntry.Text, B_Array);
    
    			for (int i = 0; i < value.Length; i++)
    			{
    				listBox1.Items.Add(string.Concat( "CHAR =  " + (char)value[i] + "   DEC = " + value[i]));
    			}
    		}
    	}
    	catch { }
    }
    
    
    // ============ Profile.cs ==============
    
    public abstract object GetValue(string section, string entry);
    
    public virtual string[] GetValue(string section, string entry, string[] defaultValue)
    {
    	object value = this.GetValue(section, entry);
    	if (value == null)
    	{
    		return defaultValue;
    	}
    	return (string[])value;
    }
    
    public virtual byte[] GetValue(string section, string entry, byte[] defaultValue)
    {
    	object value = this.GetValue(section, entry);
    	if (value == null)
    	{
    		return defaultValue;
    	}
    	return (byte[])value;
    }
    
    
    // ================ Registry.cs =================
    
    
    public override object GetValue(string section, string entry)
    {
    	object obj;
    	this.VerifyAndAdjustSection(ref section);
    	this.VerifyAndAdjustEntry(ref entry);
    	using (Microsoft.Win32.RegistryKey subKey = this.GetSubKey(section, false, false))
    	{
    		obj = (subKey?.GetValue(entry));
    	}
    	return obj;
    }
    

    I need to know how to return the string array and byte array to the TxtValue.Text

    Here is a link to my project :

    Registry Utility

    Please help

    Thank you


    • Edited by dxe2dsf Thursday, November 29, 2018 6:34 PM
    Thursday, November 29, 2018 6:31 PM

All replies

  • How do you think that's going to work?  TxtValue is a one-line text box.  How will you present a multistring value in a way that makes sense?  That's why the project you copied puts them into a list box.

    It's easy enough to use something like StringBuilder to build up one string combining the string values, but it won't be very friendly to use.


    Tim Roberts | Driver MVP Emeritus | Providenza &amp; Boekelheide, Inc.

    Thursday, November 29, 2018 10:47 PM
  • Hello Tim

             I added the text changed code and the list box to the project.

    Try to offer help instead of criticism, we all can't be perfect coders like you.

    I have red all of your replies and every one of them is criticism, no help.

    So you have 13,080 points for criticism huh?

    I  will get an answer from someone that doesn't have a God complex

    Thursday, November 29, 2018 11:42 PM
  • Greetings dxe2dsf,

    You need a loop, similar to the way you put the strings into the ListBox, except you need to put spaces or some other delimiter between the lines as you add them to the text. Maybe something like so...

    			for (int i = 0; i < value.Length; i++)
    			{
                                this.TxtValue.Text += value[i] + " "; // Add each line, and a space between.
    			}

    But Tim is right. It won't look very good. (And he doesn't have a God complex. His criticism was constructive. Pull your head in.)
    Friday, November 30, 2018 12:24 AM
  • Based on information on MVP Reconnect site, he was MVP for Windows Hardware/Driver since 1995 and had awarded 22 times. I guess people are expected do their homework before asking driver related questions.
    Friday, November 30, 2018 5:55 AM
    Answerer
  • I think you are being overly sensitive, which is not a good attribute in an online forum.  I do not see my response to you as being critical.  I asked how you thought it was going to work.  That was intended to get you to literally think about how it was going to work, because in thinking about it, it would lead you to understand the limitations of what you were proposing.  Those of us who help out here should always aim to lead users to their own solutions, rather than have someone just hand you a canned answer from which you will learn nothing.

    Further, I DID give you a proposed solution, using StringBuilder.


    Tim Roberts | Driver MVP Emeritus | Providenza &amp; Boekelheide, Inc.

    Saturday, December 1, 2018 12:21 AM
  • People are expected to do their homework before asking ANY questions.  With the exception of the Microsoft contingent staff, everyone answering questions here is a volunteer, sharing our knowledge and experience out of our own good will.  It's a matter of respect.

    Tim Roberts | Driver MVP Emeritus | Providenza &amp; Boekelheide, Inc.

    Saturday, December 1, 2018 12:23 AM
  • I agree it's a matter of respect and this is what they should do before asking questions.

    However since "Visual C#" is a beginner-level-facing forum, there is relatively more newcomers here. I would relax the standard a bit when answering question here.

    Monday, December 3, 2018 1:13 AM
    Answerer