Results 1 to 4 of 4

Thread: wild card

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2007
    Posts
    18

    wild card

    I'm converting over from VB6 and what I want to do seems like it should be really easy, but I'm having trouble... this is part of my program, looking for a way to pull images from a directory and I need to be able to use wildcards to search... can someone please help??

    here is my code ->

    Code:
    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;
    
    namespace WindowsApplication10
    {
    	/// <summary>
    	/// Summary description for Form1.
    	/// </summary>
    	public class Form1 : System.Windows.Forms.Form
    	{
    		private System.Windows.Forms.PictureBox pictureBox1;
    		private System.Windows.Forms.TextBox textBox1;
    		private System.Windows.Forms.Button button1;
    		private System.Windows.Forms.Label label1;
    		private System.Data.OleDb.OleDbCommand oleDbSelectCommand1;
    		private System.Data.OleDb.OleDbCommand oleDbInsertCommand1;
    		private System.Data.OleDb.OleDbCommand oleDbUpdateCommand1;
    		private System.Data.OleDb.OleDbCommand oleDbDeleteCommand1;
    		private System.Data.OleDb.OleDbDataAdapter oleDbDataAdapter1;
    		/// <summary>
    		/// Required designer variable.
    		/// </summary>
    		private System.ComponentModel.Container components = null;
    
    	
    		public Form1()
    		{
    		
    			
    			//filename = textBox1;
    
    			//
    			// Required for Windows Form Designer support
    			//
    			InitializeComponent();
    
    			//
    			// TODO: Add any constructor code after InitializeComponent call
    			//
    		}
    
    		/// <summary>
    		/// Clean up any resources being used.
    		/// </summary>
    		protected override void Dispose( bool disposing )
    		{
    			if( disposing )
    			{
    				if (components != null) 
    				{
    					components.Dispose();
    				}
    			}
    			base.Dispose( disposing );
    		}
    
    		#region Windows Form Designer generated code
    		/// <summary>
    		/// Required method for Designer support - do not modify
    		/// the contents of this method with the code editor.
    		/// </summary>
    		private void InitializeComponent()
    		{
    			System.Configuration.AppSettingsReader configurationAppSettings = new System.Configuration.AppSettingsReader();
    			this.pictureBox1 = new System.Windows.Forms.PictureBox();
    			this.textBox1 = new System.Windows.Forms.TextBox();
    			this.button1 = new System.Windows.Forms.Button();
    			this.label1 = new System.Windows.Forms.Label();
    			this.oleDbSelectCommand1 = new System.Data.OleDb.OleDbCommand();
    			this.oleDbInsertCommand1 = new System.Data.OleDb.OleDbCommand();
    			this.oleDbUpdateCommand1 = new System.Data.OleDb.OleDbCommand();
    			this.oleDbDeleteCommand1 = new System.Data.OleDb.OleDbCommand();
    			this.oleDbDataAdapter1 = new System.Data.OleDb.OleDbDataAdapter();
    			this.SuspendLayout();
    			// 
    			// pictureBox1
    			// 
    			this.pictureBox1.Location = new System.Drawing.Point(24, 80);
    			this.pictureBox1.Name = "pictureBox1";
    			this.pictureBox1.Size = new System.Drawing.Size(256, 192);
    			this.pictureBox1.TabIndex = 0;
    			this.pictureBox1.TabStop = false;
    			// 
    			// textBox1
    			// 
    			this.textBox1.AcceptsReturn = ((bool)(configurationAppSettings.GetValue("textBox1.AcceptsReturn", typeof(bool))));
    			this.textBox1.Location = new System.Drawing.Point(16, 32);
    			this.textBox1.MaxLength = ((int)(configurationAppSettings.GetValue("textBox1.MaxLength", typeof(int))));
    			this.textBox1.Name = "textBox1";
    			this.textBox1.Size = new System.Drawing.Size(104, 20);
    			this.textBox1.TabIndex = 1;
    			this.textBox1.Text = "textBox1";
    			// 
    			// button1
    			// 
    			this.button1.Location = new System.Drawing.Point(168, 16);
    			this.button1.Name = "button1";
    			this.button1.Size = new System.Drawing.Size(88, 48);
    			this.button1.TabIndex = 2;
    			this.button1.Text = "button1";
    			this.button1.Click += new System.EventHandler(this.button1_Click);
    			// 
    			// label1
    			// 
    			this.label1.Location = new System.Drawing.Point(104, 40);
    			this.label1.Name = "label1";
    			this.label1.Size = new System.Drawing.Size(96, 48);
    			this.label1.TabIndex = 3;
    			this.label1.Text = "label1";
    			// 
    			// oleDbDataAdapter1
    			// 
    			this.oleDbDataAdapter1.DeleteCommand = this.oleDbDeleteCommand1;
    			this.oleDbDataAdapter1.InsertCommand = this.oleDbInsertCommand1;
    			this.oleDbDataAdapter1.SelectCommand = this.oleDbSelectCommand1;
    			this.oleDbDataAdapter1.UpdateCommand = this.oleDbUpdateCommand1;
    			// 
    			// Form1
    			// 
    			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
    			this.ClientSize = new System.Drawing.Size(292, 273);
    			this.Controls.Add(this.label1);
    			this.Controls.Add(this.button1);
    			this.Controls.Add(this.textBox1);
    			this.Controls.Add(this.pictureBox1);
    			this.Name = "Form1";
    			this.Text = "Form1";
    			this.ResumeLayout(false);
    
    		}
    		#endregion
    
    		/// <summary>
    		/// The main entry point for the application.
    		/// </summary>
    		[STAThread]		
    		
    		static void Main() 
    		{
    			Application.Run(new Form1());
    		}
    
    		private void button1_Click(object sender, System.EventArgs e)
    		{
    
    			string txt = textBox1.Text;
    			textBox1.MaxLength=5;
    		pictureBox1.Image = 
    				new Bitmap(@"c:\images\" + % + txt + % + ".jpg");
    					}		
    		
    	}
    }



    -----------------------------------------------------------------------------------------------------------------


    I see that % doesn't work as a wild card like I had hoped... I tried the following, but really no idea how to integrate of if it is correct...


    string titleKeyword = "%" + txtTitleKeyword.Text + "%";
    this.OleDbDataAdapter1.SelectCommand.Parameters[1].Value = titleKeyword;
    this.OleDbDataAdapter1.SelectCommand.Parameters["Title_Keyword"].Value = titleKeyword

  2. #2
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724

    Re: wild card

    Hmm, totally wrong tree. You're looking for the System.IO.DirectoryInfo class; it has a method - "GetFiles" - that accepts a parameter. You use this to search for files; the usual wildcards apply (*, ?).

    On to your code:
    string txt = textBox1.Text;
    You only really need to use a local variable for a property when you access it more than once. This is somewhat inefficient.

    textBox1.MaxLength=5;
    You can declaratively set this - use the Properties window in your designer.

    pictureBox1.Image = new Bitmap(@"c:\images\" + % + txt + % + ".jpg");
    This should give you compiler errors; syntactically incorrect.
    Also, you will find that you'll get a FileNotFoundException as the Bitmap search will, in all probability, search for a specific file.

    What exactly are you looking to do here?

  3. #3

    Thread Starter
    Junior Member
    Join Date
    May 2007
    Posts
    18

    Re: wild card

    Quote Originally Posted by axion_sa
    pictureBox1.Image = new Bitmap(@"c:\images\" + % + txt + % + ".jpg");
    This should give you compiler errors; syntactically incorrect.
    Also, you will find that you'll get a FileNotFoundException as the Bitmap search will, in all probability, search for a specific file.

    What exactly are you looking to do here?

    I'm really just trying to learn c# so I can eventually move my Vb6 image viewing program to c#... I am trying to figure out the code for this portion of pulling images from an image folder using wild cards (%), which maybe needs to be * from what you are saying, but I tried that also with no luck.

    searching folder:
    c:\images\
    for image files:

    so it will pull up images with OKAY in the string (just as an example).. where OKAY is the text input...
    jlsjlfdsldsdflsldfjOKAYjslfdslsldfjl.jpg
    jsljOKAYjljsd.jpg

  4. #4
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724

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