WeaponX 0 Report post Posted June 22, 2005 Hi, I'm using Visual Basic 6 and I want to know how I can take input from the clipboard and compare it to the entries I have in my program (maybe using an array?).For example, if the user copies these text into the clipboard:123:45345:57I will have a button where the user can click to do the comparisons. Let's say I have this somewhere in my program:124:55993:24345:57So I want it to output the difference into a textbox:123:45will be outputted since it's not listed in my program.How can this be done? I will have hundreds of lines (the above are just made up samples of what I want).Thanks. Share this post Link to post Share on other sites
miCRoSCoPiC^eaRthLinG 0 Report post Posted June 22, 2005 I've got a solution for you - but unfortunately not in VB6. I'm afraid I'm way better with VB & C# - the .NET versions than I ever was (or need to be) with VB6. See if you can find some similar syntax in VB6 and port this code to suit you... We'll start by writing a small function that will parse the clipboard contents and return all the text found in it as one whole long string. First of all start a new project as Standard Windows Application and in the Code View add the following code: Private Function GetTextFromClipboard () As String Dim ClipboardData As IDataObject = Clipboard.GetDataObject() With ClipboardData If .GetDataPresent(DataFormats.Text) Then Return _ .GetData(DataFormats.Text) End With End Function The IDataObject interface is used by the Clipboard class and in drag-and-drop operations. Source: MSDN I dont think much explanation is needed in way here - we're simply defining an object named ClipboardData of the interface type IDataObject. The member method GetDataPresent fetches you the data from the clipboard which corresponds to the format specified within the paranthesis (here DataFormats.Text). The "If" checks whether there is any text data present and if true, returns it using this function. Now all you need to do is use this function and store the text data from the clipboard into a String variable. Say, Dim ClipData As StringClipData = GetTextFromClipboard () Now going back to your original question... supposing you have two lines of text in the clipboard:123:45 345:57 This is stored in the ClipData variable as one string broken in the middle by a carriage return - in terms of VB, which can be located by matching against a CHR(13). But you don't need to go that way. VB provides a very cool function called split which is the contemporary of the explode function in PHP - it essentially breaks up a string into several parts and stores each part serially in an array based on a common delimiter. Here the delimeter is Carriage Return or CHR(13)... so all we need to do is define and empty array and use split. Dim DataLines () as StringDataLines = split ( ClipData, Chr(13), -1 ) That should store the values 123:45 and 345:57 into position 0 and 1 of the array... Now simply pass this through a for-next loop or while-wend loop and match each position against the values stored elsewhere in your program... and print out the difference. Hope this helps... Regards, m^e Share this post Link to post Share on other sites
WeaponX 0 Report post Posted June 22, 2005 Thanks for the quick reply m^e. I wish I was a better programmer LOL. I will definitely take a look at the code you posted there and try to understand it better. I actually did something similar to this in C but it's not so useful anymore since I need this feature built into my VB program instead.Will post back if anything. Need to learn .NET by now also LOL. Thanks again. Share this post Link to post Share on other sites
iGuest 3 Report post Posted May 23, 2011 compare 2 excel filesVB6 Compare And Output DifferenceHiI need to create a program that needs to compare 2 excel files, for example sample1.Xls contains 100 invoices and sample2.Xls contains also 90 invoices. I need to know which are those invoices that were in sample2.XlsCurrently I created interface wherein I will upload both excel files and my problem is how to start coding in the main process. Appreciate your help very much. Thanks a lot. -question by Ana Aguilar Share this post Link to post Share on other sites